Could be a tricky question or maybe not feasible, but I've been scratching my head over it for quite some time and just can't seem to crack it. Appreciate any help!
The T generic creates a union type:
const arrayToArray = <T>(values: T[]) => values;
When I call the function with:
const result = arrayToArray([1, 'hi', 3]);
It results in the type:
const result: (string | number)[]
My desired output is:
const result: [number, string, number]
I want 'one'
and 'three'
to trigger a type error as they are not numbers.
const useResultType: typeof result = ['one', 'two', 'three'];