Cheatsheets

TypeScript Cheatsheet

Use this TypeScript cheatsheet for high-frequency syntax and type-system patterns without turning everyday code into unnecessary abstractions.

Quick reference

Values and collections

Primitiveconst count: number = 3
Arrayconst ids: string[] = []
Tupletype Point = [number, number]
Readonlyreadonly string[]

Objects

Type aliastype User = { id: string; name: string }
Interfaceinterface User { id: string; name: string }
OptionalavatarUrl?: string
Index signatureRecord<string, number>

Combining types

Uniontype State = 'idle' | 'loading' | 'error'
Intersectiontype Admin = User & Permissions
Key unionkeyof User
Indexed accessUser['id']

Narrowing

typeofif (typeof value === 'string')
Property checkif ('error' in result)
Type predicatefunction isUser(value: unknown): value is User
Exhaustiveconst unreachable: never = state

Generics and utilities

Generic functionfunction first<T>(items: T[]): T | undefined
PartialPartial<User>
PickPick<User, 'id' | 'name'>
OmitOmit<User, 'password'>
Return typeReturnType<typeof buildUser>

Functions and safety

Function(value: string) => void
Unknownvalue: unknown

Narrow before use.

Anyvalue: any

Disables checking; keep escape hatches isolated.

Async resultPromise<User>

Examples

CodeDiscriminated union
type Result<T> =
  | { status: "success"; data: T }
  | { status: "error"; message: string };

function render(result: Result<string>) {
  return result.status === "success" ? result.data : result.message;
}
CodeTyped React props
type ButtonProps = {
  children: React.ReactNode;
  onClick: () => void;
  disabled?: boolean;
};

TypeScript FAQ

What is included in the TypeScript cheatsheet?

TypeScript Cheatsheet includes quick reference sections, practical examples, common mistakes, tips and links to related DevKitYard tools.

Is the TypeScript cheatsheet interactive?

This cheatsheet is a static quick reference focused on concise commands, syntax and examples.

When should I use this TypeScript reference?

Use it when you need to recall syntax, compare common patterns or avoid mistakes without opening a long tutorial.

What should I use after reading this cheatsheet?

Use related DevKitYard tools such as JSON Formatter when you need to format, validate, generate or inspect real output.