kaleidawave/ezno

Array slice infer patterns

kaleidawave opened this issue · 0 comments

The following code should type-check fine

type Head<T> = T extends [infer H, ...Array<any>] ? H : never;

type Tail<T> = T extends [any, ...infer Tail] ? Tail : [];

1 satisfies Head<[1, 2, 3, 4, 5]>;
[2, 3, 4, 5] satisfies Tail<[1, 2, 3, 4, 5]>;

There is some current problems with representing spread arrays patterns. It isn't great as it reuses the same object helper as regular expression space array literals (and so doesn't create an anonymous object literal type). Maybe this could be handled regularly, maybe there needs to be a special fn extract_as_slice helper method?