Problem (presumed)
Starting off with a caveat that this is what I presume the problem to be because my understanding of TypeScript isn't extremely deep. This explanation may not be totally correct or may not be elaborated well.
Your function is declared without an explicit return type:
function makePair<T, S> () { ... }
As a result, TypeScript will attempt to infer the return type from the expression returned:
return [ getPair, setPair ];
// ^^^^^^^^^^^^^^^^^^^^
// The expression returned
You may think the expression's type is supposed to be inferred to:
[() => { first: T, second: S }, (x: T, y: S) => void]
However this doesn't happen. It actually got inferred to:
((x: T, y: S) => void)[]
As arrays are mutable, TypeScript cannot guarantee your type will always be [() => { first: T, second: S }, (x: T, y: S) => void]. It therefore widens the type to ((x: T, y: S) => void)[]. (Although why it widened it to that, I'm not certain and it could be a bug).
Solution
You'll need to explicitly type your return type. Examples:
function makePair<T, S> (): [() => { first: T, second: S }, (x: T, y: S) => void] {
// ...
return [ getPair, setPair ];
}
TypeScript Playground
function makePair<T, S> () {
// ...
return [ getPair, setPair ] as [typeof getPair, typeof setPair];
}
TypeScript Playground
Or make a const assertion to force the compiler to not widen types:
function makePair<T, S> () {
// ...
return [ getPair, setPair ] as const;
}
TypeScript Playground
Further reading
getPairis not expecting any arguments.