I have a union type, PromptOptions
:
type PromptOptions =
| BasePromptOptions
| BooleanPromptOptions
| StringPromptOptions
type BasePromptOptions = {
kind: string | (() => string)
};
type BooleanPromptOptions = { kind: 'confirm' };
type StringPromptOptions = {
kind: 'input' | 'invisible' | 'list' | 'password' | 'text';
};
What I'm trying to do:
Given an arbitrary type, type Lookup = { kind: 'invisible' }
, I want to use type ExtractedType<T> = Extract<PromptOptions, T>
with the end result of ExtractedType<Lookup> = StringPromptOptions
.
This works if I pass in a type that exactly matches a prompt option (ExtractedType<{ kind: 'confirm' }> = BooleanPromptOptions
), but something like this: ExtractedType<{ kind: 'invisible' }> = never
when I want/expect it to be StringPromptOptions
.
Clearly this isn't correct, but I want to do something like Extract<PromptOptions, T extends <PromptOptions['kind']>>
, I'm just not sure how (or if this is even possible).