What I want to do is pass an array to a function and receive the values of this array as a tuple in another function.
myFunction(
(a, b) => null,
{
params: [true, 1]
}
);
In the example above, I want typings: a: boolean
and b: number
. Instead I receive a: boolean | number
and b: boolean | number
.
Please keep in mind that I want the length of params to be variable. Also [1, false, 'string', {}]
should be possible.
As I have read this has something to do with mapped tuples? But I really don't get it.
My current implementation looks like this:
function myFunction<P extends any[]>(
fn: (...params: P) => null,
options: { params: P }) {
...
}
--
What actually works is this:
myFunction(
(a, b) => null,
{
params: [true, 1] as [boolean, number]
}
);
But I really don't want to type-cast all the time to make it work :/