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

Support for TupleToUnion #64

Closed
haejunejung opened this issue Sep 2, 2024 · 0 comments · Fixed by #67
Closed

Support for TupleToUnion #64

haejunejung opened this issue Sep 2, 2024 · 0 comments · Fixed by #67
Labels
enhancement New feature or request

Comments

@haejunejung
Copy link
Owner

It provides support for TupleToUnion.

There are some situations that need to change tuple to union type.
It is more detailed example for API Response that is used TupleToUnion.

type ApiResponse = [number, string, boolean, { key: string }];
type AllowedValues = TupleToUnion<ApiResponse>; // number | string | boolean | { key: string }

function handler (response: AllowedValues) {
 if (typeof response === 'number') { // }
 else if (typeof response === 'string) { // }
 else if (typeof response === 'boolean) { // }
 else { // }
}
@haejunejung haejunejung added the enhancement New feature or request label Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant