Roadmap › 4. Frontend › Step 44
TS

TypeScript — Types, Generics and Real-World Patterns

Why TypeScript, basic and object types, interfaces vs type aliases, unions and narrowing, functions, classes, generics, utility types, mapped and conditional types, modules, tsconfig and strict mode, typing API calls for Angular/React, and the TypeScript interview questions.
What it is & where it is used

TypeScript is JavaScript with a static type system, created by Microsoft (lead designer Anders Hejlsberg, also the designer of C#). TypeScript code is compiled (transpiled) to plain JavaScript; types exist only at compile time and are erased at runtime.

Why teams use it:

  • Catches errors before running (typos, wrong argument types, undefined access).
  • IntelliSense, safe refactoring and self-documenting APIs.
  • Required by Angular; the default for React (Vite, Next.js) and Vue 3 projects; familiar to C# developers.
C# conceptTypeScript equivalent
class, interface, access modifiersSame keywords (interfaces are structural, not nominal)
Generics List<T>Generics Array<T>, Promise<T>
enumenum or (preferred) union of string literals
Nullable string?string | undefined, optional prop?:
async/await + Task<T>async/await + Promise<T>
LINQArray methods map, filter, reduce
Versions & history
YearVersionHighlights
20120.8First public release
20162.0strictNullChecks, never, control-flow analysis
20183.0unknown, tuples in rest parameters, project references
20204.0–4.1Variadic tuples, template literal types, key remapping
20224.9satisfies operator
20235.0Standard (TC39) decorators, const type parameters, faster builds
20245.4–5.7NoInfer, inferred type predicates, --erasableSyntaxOnly prep
20255.8–5.9Node 18+ module modes, import defer; TypeScript 7 native compiler (Go port, ~10× faster) in preview

Node.js 22.6+/23+ can run .ts files directly by stripping types (no type checking) — type-check with tsc --noEmit.

Lifecycle

From .ts file to running code:

  1. Write .ts/.tsx with types.
  2. The type checker (tsc or the editor's language service) reports errors using tsconfig.json settings.
  3. Transpile to JavaScript (tsc, esbuild, SWC, Babel, Vite, Angular CLI) — types are erased; syntax down-levelled to the target.
  4. Bundle (Vite/Rollup/webpack/esbuild) with imports resolved per module/moduleResolution.
  5. Run in the browser or Node.js. At runtime there are no types — validate external data (API responses, forms) with code or a schema library (Zod).
Tools used to develop
  • tsc compiler, tsconfig.json, ts-node/tsx to run TS in Node.
  • VS Code (built-in TS language service), TypeScript Playground (typescriptlang.org/play).
  • Bundlers: Vite, esbuild, SWC, Angular CLI, Next.js.
  • Lint: ESLint + typescript-eslint; format: Prettier.
  • Runtime validation: Zod, Valibot; API types from OpenAPI: openapi-typescript, NSwag, Orval.
  • Testing: Vitest, Jest (ts-jest), Playwright.