TypeScript
Basic Types
string—Text type
number—Integer or float type
boolean—true or false
null / undefined—Absence of value
any—Opt out of type checking
unknown—Type-safe any (must narrow)
never—Unreachable code type
void—No return value
bigint—Large integer type
symbol—Unique 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: string—Required property
age?: number—Optional property
readonly id: number—Immutable property
[key: string]: any—Index signature
extends BaseInterface—Inherit interface
interface A extends B, C—Multiple inheritance
(x: number): string—Call signature
Type Aliases & Unions
type ID = string | number—Union type alias
type A = B & C—Intersection type
type Dir = "N" | "S"—String literal union
type Nullable<T> = T | null—Generic type alias
type Fn = (x: number) => void—Function type alias
type Pair = [string, number]—Tuple type alias
type Obj = { [K in Keys]: V }—Mapped type
Generics
function fn<T>(x: T): T—Generic 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 R—Infer 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 Class—Class type guard
"prop" in obj—Property existence guard
x is Type—Custom type predicate
as Type—Type assertion
satisfies Type—Validate without widening
x!.prop—Non-null assertion
Enums & Advanced
enum Dir { Up, Down }—Numeric enum
enum S { A = "a" }—String enum
const enum—Inlined at compile time
as const—Literal type assertion
declare module "x"—Ambient module declaration
namespace N { }—Namespace grouping
type T = typeof obj—Type from runtime value
keyof T—Union of key names
allprintabledoc.com