Adds a type field to a type. Useful when creating discriminant union types.
type
type Base = { data: string };type MyUnion = Discriminant<Base, 'base64'> | Discriminant<Base, 'hex'>;const base64: MyUnion = { data: 'aGVsbG8=', type: 'base64' };if (base64.type === 'base64') { console.log(base64.data);} Copy
type Base = { data: string };type MyUnion = Discriminant<Base, 'base64'> | Discriminant<Base, 'hex'>;const base64: MyUnion = { data: 'aGVsbG8=', type: 'base64' };if (base64.type === 'base64') { console.log(base64.data);}
Adds a
typefield to a type. Useful when creating discriminant union types.