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

4484 - IsTuple #32215

Open
gasmg opened this issue Feb 14, 2024 · 0 comments
Open

4484 - IsTuple #32215

gasmg opened this issue Feb 14, 2024 · 0 comments
Labels
4484 answer Share answers/solutions to a question en in English

Comments

@gasmg
Copy link

gasmg commented Feb 14, 2024

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

type TupleOrReadonlyTuple<T extends readonly any[]> = "push" extends keyof T ? [...ReadonlyTuple<T>] : ReadonlyTuple<T>;

type IsTuple<T> = [T] extends [never]
	? false
	: T extends ReadonlyArray<any>
	? T extends TupleOrReadonlyTuple<T>
		? true
		: false
	: false;
@gasmg gasmg added answer Share answers/solutions to a question en in English labels Feb 14, 2024
@github-actions github-actions bot added the 4484 label Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4484 answer Share answers/solutions to a question en in English
Projects
None yet
Development

No branches or pull requests

1 participant