Type-safe JavaScript at scale.
2 topics
TypeScript adds static types to JavaScript. Primitive types: string, number, boolean, null, undefined, symbol, bigint. Object types: interfaces and type aliases. Arrays: string[], Array<number>. Union types (A | B), intersection types (A & B), literal types, and enums. Type inference: TS infers types when possible. Type assertions (as Type) for when you know more than the compiler.
2 resources
Generics: write reusable code that works with any type while maintaining type safety. Generic functions, interfaces, and classes. Constraints (extends) to limit generic types. Built-in utility types: Partial<T>, Required<T>, Pick<T,K>, Omit<T,K>, Record<K,V>, Readonly<T>, ReturnType<T>, Parameters<T>. Conditional types (T extends U ? X : Y), mapped types, and template literal types for advanced type manipulation.
Discriminated unions (tagged unions with exhaustive checks), type narrowing (typeof, instanceof, in, custom type guards), function overloads, declaration merging, module augmentation. The infer keyword for extracting types. Recursive types, variadic tuple types, and satisfies operator (TS 5.0+). Strict mode: strict null checks, no implicit any.
tsconfig.json configuration: target, module, strict, paths. Using TS with React (FC, events, refs, generic components). Type-safe API clients with Zod + tRPC or OpenAPI codegen. Declaration files (.d.ts) for untyped libraries. Monorepo setup with project references. Performance: avoid overly complex types that slow down the compiler.