Built-in Types
Quick reference to the built-in types TypeScript provides out of the box — primitive, special, structural, and standard library.
Primitive types
| Type | Example |
|---|---|
string | 'hi', "hi", `tpl ${x}` |
number | 42, 3.14 |
boolean | true, false |
bigint | 9007n |
symbol | Symbol('id') |
null | null |
undefined | undefined |
Special types
| Type | Use for |
|---|---|
any | Opt-out — disables checks for this value. |
unknown | "I don't know yet — narrow before use." |
never | Functions that never return; bottom type. |
void | Returns nothing useful. |
object | Any non-primitive (rarely useful). |
Structural shapes
TS
// Arrays
const xs: number[] = [];
const ys: Array<number> = [];
const ro: readonly number[] = [];
const ros: ReadonlyArray<number> = [];
// Tuples
const p: [number, number] = [3, 4];
const named: [x: number, y: number] = [3, 4];
// Records / dicts
const r: Record<string, number> = {};
const r2: { [key: string]: number } = {};
// Functions
type Fn = (a: number, b: number) => number;
Standard library types
| Type | Comes from |
|---|---|
Array<T>, Map<K, V>, Set<T>, WeakMap<K, V> | JS standard lib |
Promise<T>, Awaited<T> | Async / promises |
Date, RegExp, Error | JS classes |
Iterable<T>, Iterator<T>, Generator<T> | Iteration |
JSON, Math, Object | Global namespaces |
DOM / browser types (with lib: ["DOM"])
HTMLElement, HTMLInputElement, Document, Window, Event, MouseEvent, KeyboardEvent, Response, Request, FormData, URL, URLSearchParams, ReadableStream, AbortController, … all available globally.
Node types (with @types/node)
Buffer, NodeJS.ProcessEnv, fs, path, http, … via import. process, global, require available as globals.
Tip: Open
lib.es*.d.ts in node_modules/typescript/lib to see exactly what's available. It's surprisingly readable.Example
Example
// Primitives: string | number | boolean | bigint | symbol
// Special: any | unknown | never | void
// Containers: T[] | Array<T> | [a, b] | { k: V } | Record<K, V>
// Functions: (a: T) => U
// Promises: Promise<T>
// Sets/Maps: Set<T> | Map<K, V> | WeakMap<K, V>
console.log('TS is a superset — every JS type is also a TS type');
Try it Yourself »
Exercise
Promise of a User is written…
<User>
PascalCase; seven chars.
Discussion
Loading…