TypeScript

Basic Types

stringText type
numberInteger or float type
booleantrue or false
null / undefinedAbsence of value
anyOpt out of type checking
unknownType-safe any (must narrow)
neverUnreachable code type
voidNo return value
bigintLarge integer type
symbolUnique symbol type

Arrays & Tuples

string[]Array of strings
Array<number>Generic array syntax
[string, number]Tuple type
readonly string[]Immutable array
T[][]2D array
[string, ...number[]]Variadic tuple

Interfaces

interface User { }Object shape definition
name: stringRequired property
age?: numberOptional property
readonly id: numberImmutable property
[key: string]: anyIndex signature
extends BaseInterfaceInherit interface
interface A extends B, CMultiple inheritance
(x: number): stringCall signature

Type Aliases & Unions

type ID = string | numberUnion type alias
type A = B & CIntersection type
type Dir = "N" | "S"String literal union
type Nullable<T> = T | nullGeneric type alias
type Fn = (x: number) => voidFunction type alias
type Pair = [string, number]Tuple type alias
type Obj = { [K in Keys]: V }Mapped type

Generics

function fn<T>(x: T): TGeneric function
interface Box<T> { val: T }Generic interface
<T extends Base>Constrained generic
<T = string>Default generic type
<T extends keyof O>Constrain to object keys
class Box<T> { }Generic class
<K, V>Multiple type params
infer RInfer type in conditional

Utility Types

Partial<T>All props optional
Required<T>All props required
Readonly<T>All props readonly
Pick<T, K>Select subset of props
Omit<T, K>Exclude props
Record<K, V>Map keys to values
Exclude<T, U>Remove union members
Extract<T, U>Keep matching members
ReturnType<T>Function return type
Parameters<T>Function param types
NonNullable<T>Remove null/undefined
Awaited<T>Unwrap Promise type

Type Narrowing

typeof x === "string"Primitive type guard
x instanceof ClassClass type guard
"prop" in objProperty existence guard
x is TypeCustom type predicate
as TypeType assertion
satisfies TypeValidate without widening
x!.propNon-null assertion

Enums & Advanced

enum Dir { Up, Down }Numeric enum
enum S { A = "a" }String enum
const enumInlined at compile time
as constLiteral type assertion
declare module "x"Ambient module declaration
namespace N { }Namespace grouping
type T = typeof objType from runtime value
keyof TUnion of key names
allprintabledoc.com