Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array slice infer patterns #181

Open
kaleidawave opened this issue Aug 6, 2024 · 0 comments
Open

Array slice infer patterns #181

kaleidawave opened this issue Aug 6, 2024 · 0 comments
Assignees
Labels
needs-investigation Further information is requested subtyping Related to comparing two types tsc-behaviour Trying to match TSC behaviour

Comments

@kaleidawave
Copy link
Owner

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?

@kaleidawave kaleidawave self-assigned this Aug 6, 2024
@kaleidawave kaleidawave added needs-investigation Further information is requested subtyping Related to comparing two types tsc-behaviour Trying to match TSC behaviour labels Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-investigation Further information is requested subtyping Related to comparing two types tsc-behaviour Trying to match TSC behaviour
Projects
None yet
Development

No branches or pull requests

1 participant