For example, let's say there's a code below.
type MyType = 'a' | 'b' | 'c';
const a = [3, 5, 'a', 'b'] as const;
const func = (arg: readonly [number, number, ...MyType[]]) => {
const myTypeArr = arg.slice(2); // i want this type "MyType[]" !!!
};
func(a);
I hope that the "myTypeArr" variable is inferred as MyType[].
However, it is actually inferred as (number | MyType)[].
I did a search to implement it, but I couldn't.
Can use destructuring to achieve this:
type MyType = 'a' | 'b' | 'c';
const a = [3, 5, 'a', 'b'] as const;
const func = (arg: readonly [number, number, ...MyType[]]) => {
// myTypeArr will have type MyType[]
const [ , , ...myTypeArr] = arg;
};
func(a);