Skip to content

webshrine / stdtyp/src / MaybeLiteral

Type Alias: MaybeLiteral<T>

MaybeLiteral<T>: T | string & object

Allows string to be acceptable with T literals types without loosing these literal

Type Parameters

T extends PropertyKey

Example

ts
type SomeLiterals = 'a' | 'b' | 'c'
type MaybeSomeLiterals = MaybeLiteral<SomeLiterals>
const literal1: MaybeSomeLiterals = 'a' // ok
const literal2: MaybeSomeLiterals = 'other literal' // still ok and IDE can suggest source literals

Defined in

packages/stdtyp/src/utilities/maybe.ts:36