Basic types, Literal Types
primitive types
let x: number // includes NaN and Infinity
let x: string
let x: boolean
let x: null
let x: undefined
let x: bigint
let x: symbol
loose types (do not use)
The object and {} types are too broad to be useful:
- object covers everything except primitive types, aka plain objects, arrays, functions, sets etc.
- {} covers everything except null or undefined.
let x: object
let x: {}
literal types
The type consists of a single literal:
type T = "unavailable"
union of literals
We create a union of literal types. For example, a union type of string literals:
type T = "unavailable" | "available"