types-kit.literalunion.md

September 4, 2023 ยท View on GitHub

Home > types-kit > LiteralUnion

LiteralUnion type

Allows creating a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union.

Signature:

export type LiteralUnion<T extends U, U> = T | (U & Omit<U, PropertyKey>)

Example

type Foo = LiteralUnion<'dog' | 'cat', string>
const foo:Foo = '' // You will get auto-completion for `dog` and `cat` literals.