type R = IsStringLiteral<string> // false
type R = IsStringLiteral<'a'> // true
type R = IsStringLiteral<`${number}`> // true
type R = IsStringLiteral<never> // false
type R = IsStringLiteral<unknown> // false
type R = IsStringLiteral<'a' | boolean> // boolean
🔢 customize
Filter to ensure T
is a string literal(s), otherwise returns never
.
type R = IsStringLiteral<string, { selection: 'filter' }> // never
type R = IsStringLiteral<'a', { selection: 'filter' }> // 'a'
type R = IsStringLiteral<never, { selection: 'filter' }> // never
type R = IsStringLiteral<unknown, { selection: 'filter' }> // never
type R = IsStringLiteral<'a' | boolean, { selection: 'filter' }> // 'a'
🔢 customize:
Disable distribution of union types.
type R = IsStringLiteral<'abc' | 1> // boolean
type R = IsStringLiteral<'abc' | 1, { distributive: false }> // false
🔢 customize:
Check if T
is exactly a string literal, excluding template literals.
type R = IsStringLiteral<'${number}'> // true
type R = IsStringLiteral<'${number}', { exact: true }> // false
🔢 customize
Use unique branch identifiers to allow precise processing of the result.
🎭 predicate
Validate if
T
is a string literal(s).