TypeScript TypeScript 5.x
TypeScript 5 Quick Reference
Essential TypeScript syntax: annotations, interfaces, discriminated unions, generics, and utility types.
type PublicUser = Omit<User, 'passwordHash'>;
Core Types & Narrowing
| Syntax | Purpose | Example |
|---|---|---|
readonly / ? | Immutable / optional fields | interface User { readonly id: string; bio?: string; } |
A | B | Union & literal types | type Status = "idle" | "loading" | "done"; |
unknown | Safe top type (narrow first) | if (typeof x === "string") x.toUpperCase(); |
<T, K extends keyof T> | Constrained generics | function get<T, K extends keyof T>(o: T, k: K) |
Utility Types
| Utility | Effect | Example |
|---|---|---|
Partial<T> | All properties optional | Partial<User> |
Pick<T, K> | Keep selected keys | Pick<User, "id" | "name"> |
Omit<T, K> | Remove selected keys | Omit<User, "password"> |
Record<K, V> | Typed key-value object | Record<string, number> |