Type Alias IsLiteral<T, Then, Else>

IsLiteral<T, Then, Else>: number extends T
    ? Else
    : string extends T
        ? Else
        : boolean extends T
            ? Else
            : symbol extends T
                ? Else
                : bigint extends T
                    ? Else
                    : Then

Validate if specified type is a scalar literal.

🎭 predicate

Type Parameters

  • T extends
        | number
        | boolean
        | bigint
        | string
        | symbol
  • Then = true
  • Else = false
type R = IsLiteral<string> // false
type R = IsLiteral<number> // false
type R = IsLiteral<boolean> // false
type R = IsLiteral<bigint> // false
type R = IsLiteral<symbol> // false

type R = IsLiteral<'a'> // true
type R = IsLiteral<1> // true
type R = IsLiteral<true> // true
type R = IsLiteral<1n> // true
type R = IsLiteral<typeof someSymbol> // true