We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I propose type UnionKeys<UnionType>:
UnionKeys<UnionType>
UnionType
A type-safe setting value when union is used:
type LogOptions = | { action: "openBlogPage"; data: { startTime: number } } | { action: "likeVideo"; data: { videoSrc: string } } | { action: "closeBlogPage"; data: { readingTime: number } }; const setLogOptions = <TKey extends UnionKeysOf<LogOptions>, TValue = TKey extends keyof LogOptions ? LogOptions[TKey] : never>( option: LogOptions, key: TKey, value: TValue, ) => { (option as Record<string, unknown>)[key] = value; } declare const option: LogOptions; setLogOptions(option, 'action', 'openBlogPage'); setLogOptions(option, 'data', {startTime: 1});
TS Playground – https://tsplay.dev/NnE8xw
The text was updated successfully, but these errors were encountered:
No branches or pull requests
What
I propose type
UnionKeys<UnionType>
:UnionType
Examples
A type-safe setting value when union is used:
Additional Info
TS Playground – https://tsplay.dev/NnE8xw
The text was updated successfully, but these errors were encountered: