๐ท TypeScript Dictionary
Every keyword, operator, and symbol โ with plain-English explanations.
string type-systemPrimitive type
'hello'
number type-systemPrimitive type
123
boolean type-systemPrimitive type
true
any type-systemAny type
let x: any = 123;
unknown type-systemUnknown type
let x: unknown = 123;
never type-systemNever type
function neverFunction(): never { throw new Error('Never!'); }void type-systemVoid type
function voidFunction(): void { console.log('Void!'); }null type-systemNull type
let x: null = null;
undefined type-systemUndefined type
let x: undefined = undefined;
object type-systemObject type
let x: object = {};type type-systemType definition
type User = { name: string; age: number; }enum type-systemEnum type
enum Color { Red, Green, Blue }implements type-systemImplements interface
class MyClass implements MyInterface {}interface interfacesDefines the shape of an object
interface User { id: number; name: string; }extends interfacesExtends an interface or class
interface Admin extends User { role: string; }readonly interfacesMakes a property immutable after initialization
interface Point { readonly x: number; readonly y: number; }optional-property interfacesProperty that may be absent โ marked with ?
interface Config { timeout?: number; }const-enum enumsEnum inlined at compile time โ no runtime object
const enum Status { Active = 1, Inactive = 0 }generics genericsParameterizes types for reusable code
function identity<T>(arg: T): T { return arg; }generic-constraint genericsLimits generic type with extends
function getLen<T extends { length: number }>(arg: T): number { return arg.length; }keyof advanced-typesReturns a union of the keys of a type
type Keys = keyof User; // "id" | "name"
typeof advanced-typesGets the type of a variable or expression
const config = { port: 8080 }; type Config = typeof config;infer advanced-typesInfers a type variable within a conditional type
type ReturnType<T> = T extends (...args: any[]) => infer R ? R : never;
conditional-type advanced-typesType that resolves based on a condition
type IsString<T> = T extends string ? true : false;
mapped-type advanced-typesCreates new type by transforming properties of existing type
type Nullable<T> = { [K in keyof T]: T[K] | null };union advanced-typesType that can be one of several types
type ID = string | number;
intersection advanced-typesCombines multiple types into one
type AdminUser = User & Admin;
tuple advanced-typesFixed-length array with specific types per position
let coord: [number, number] = [10, 20];
Partial utility-typesMakes all properties of T optional
function update(user: Partial<User>) {}Required utility-typesMakes all properties of T required
type FullUser = Required<User>;
Readonly utility-typesMakes all properties of T readonly
const user: Readonly<User> = { id: 1, name: 'Alice' };Record utility-typesCreates object type with keys K and values T
const roles: Record<string, string[]> = { admin: ['read','write'] };Pick utility-typesSelects a subset of properties from T
type NameOnly = Pick<User, 'name'>;
Omit utility-typesExcludes specified properties from T
type WithoutId = Omit<User, 'id'>;
Exclude utility-typesRemoves types from union T that are assignable to U
type NonString = Exclude<string | number, string>; // number
Extract utility-typesExtracts from T types assignable to U
type Strings = Extract<string | number, string>; // string
NonNullable utility-typesRemoves null and undefined from T
type Clean = NonNullable<string | null | undefined>; // string
ReturnType utility-typesGets the return type of a function type
type R = ReturnType<typeof getUser>; // User
Parameters utility-typesGets the parameter types of a function as a tuple
type P = Parameters<typeof fetch>; // [input: RequestInfo, init?: RequestInit]
Awaited utility-typesUnwraps the resolved type of a Promise
type T = Awaited<Promise<string>>; // string
as type-guardsType assertion โ tells TypeScript to treat a value as a specific type
const input = event.target as HTMLInputElement;
is type-guardsType predicate โ narrows type in if blocks
function isString(val: unknown): val is string { return typeof val === 'string'; }instanceof type-guardsChecks if a value is an instance of a class
if (err instanceof Error) { console.log(err.message); }satisfies type-guardsValidates type without widening โ preserves literal type
const palette = { red: [255,0,0] } satisfies Record<string, number[]>;non-null-assertion type-guardsAsserts value is not null/undefined with !
const el = document.getElementById('app')!;optional-chaining type-guardsShort-circuits on null/undefined with ?.
const name = user?.profile?.name;
nullish-coalescing type-guardsReturns right side when left is null or undefined
const port = config.port ?? 8080;
abstract classesDeclares a class or method that must be implemented by subclasses
abstract class Shape { abstract area(): number; }declare modulesDeclares a type without emitting JavaScript
declare const window: Window & typeof globalThis;
namespace modulesGroups related code under a named scope
namespace Utils { export function log(msg: string) {} }noImplicitAny tsconfigErrors when TypeScript cannot infer a type as not-any
// tsconfig.json: "noImplicitAny": true
strictNullChecks tsconfigMakes null and undefined not assignable to other types
// tsconfig.json: "strictNullChecks": true
strict tsconfigEnables all strict type-checking options at once
// tsconfig.json: "strict": true
target tsconfigSets the JavaScript version to compile to
// tsconfig.json: "target": "ES2022"
paths tsconfigMaps module paths to filesystem locations
// tsconfig.json: "paths": { "@/*": ["./src/*"] }async-await asyncAsync function returns a Promise; await unwraps it
async function fetchUser(id: number): Promise<User> { return await api.get(id); }Promise asyncBuilt-in generic type for async values
const p: Promise<string> = fetch(url).then(r => r.text());
template-literal-type advanced-typesCreates string union types using template syntax
type EventName = `on${Capitalize<string>}`;decorators decoratorsAnnotations that attach metadata or modify class behavior
@Component({ selector: 'app-root' }) class AppComponent {}Array built-insGeneric array type
const nums: Array<number> = [1, 2, 3];
Map built-insTyped key-value collection
const m = new Map<string, number>(); m.set('a', 1);Set built-insTyped collection of unique values
const s = new Set<string>(['a', 'b', 'a']); // size: 2