Adding a utility type for discriminated unions to select specific types using discriminator value.
Example:
export type DiscriminateUnion<T, K extends keyof T, V extends T[K]> =
T extends Record<K, V> ? T : never
export type T1 = { type: 'title', data: string } | { type: 'email', data: string } | { type: 'number', data: number } | { type: 'file': data: { url: string }}
// T2 is "{ type: 'title', data: string }"
export type T2 = DiscriminateUnion<T1, 'type', 'title'>
// T3 is "{ type: 'file': data: { url: string }"
export type T3 = DiscriminateUnion<T1, 'type', 'file'>
// T4 is "{ type: 'title', data: string } | { type: 'email', data: string }"
export type T4 = DiscriminateUnion<T1, 'type', 'title' | 'number''>
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too