Literal Union
Loosen and strictify a literal union type.
- #typescript
type Loose<T> = T | (string & {});
type Strictify<T extends string> = T extends `${infer _}` ? T : never;
type DemoA = Loose<'red' | 'blue' | 'green'>;
// 'red' | 'blue' | 'green' | (string & {})
type DemoB = Strictify<DemoA>;
// 'red' | 'blue' | 'green'