import type {IsStringLiteral} from './is-string-literal.d.ts'; import type {IsNumericLiteral} from './is-numeric-literal.d.ts'; import type {IsBooleanLiteral} from './is-boolean-literal.d.ts'; import type {IsSymbolLiteral} from './is-symbol-literal.d.ts'; import type {IsNever} from './is-never.d.ts'; import type {IfNotAnyOrNever} from './internal/type.d.ts'; import type {CollapseLiterals, UnwrapBrand} from './internal/object.d.ts'; /** Returns a boolean for whether the given type is a [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types). @example ``` import type {IsLiteral} from 'type-fest'; type A = IsLiteral<1>; //=> true type B = IsLiteral; //=> false type C = IsLiteral<1n>; //=> true type D = IsLiteral; //=> false type E = IsLiteral<'type-fest'>; //=> true type F = IsLiteral; //=> false type G = IsLiteral<`on${string}`>; //=> false declare const symbolLiteral: unique symbol; type H = IsLiteral; //=> true type I = IsLiteral; //=> false type J = IsLiteral; //=> true type K = IsLiteral; //=> true type L = IsLiteral; //=> false type M = IsLiteral<1 | 'foo' | false>; //=> true type N = IsLiteral; //=> false type O = IsLiteral<1000n | string | true>; //=> boolean ``` @category Type Guard @category Utilities */ export type IsLiteral = IfNotAnyOrNever>>; ifAny: false; ifNever: false; }>; type _IsLiteral = | (Extract extends infer Bools // We can't instantiate `IsBooleanLiteral` with `never`, // because that will add an extraneous `false` to the result if there are no booleans. ? IsNever extends true ? never : IsBooleanLiteral : never) | (IsLiteralNonBools>); type IsLiteralNonBools = T extends number | bigint ? IsNumericLiteral : T extends string ? IsStringLiteral : T extends symbol ? IsSymbolLiteral : false; export {};