# Type Alias AddTypeDiscriminant<T, K>

AddTypeDiscriminant: T & { type: K }

Adds a `type` field to a type. Useful when creating discriminant union types.

    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);
    }

#### Type Parameters

- T
- K extends string | number | symbol