Concepts

TypeScript

Typed superset of JavaScript adding optional static types, improving developer productivity, error detection, and code maintainability.

seed#typescript#javascript#types#static-analysis#tooling#dx

What it is

TypeScript is a superset of JavaScript that adds optional static types. All valid JavaScript is valid TypeScript, but TypeScript allows declaring types that the compiler verifies before execution, catching errors in development instead of production.

Why TypeScript?

  • Errors detected at compile time, not runtime
  • Intelligent IDE autocomplete
  • Safe refactoring at scale
  • Implicit documentation in types
  • De facto standard for serious JavaScript projects

Key features

  • Interfaces and types: define data shapes
  • Generics: reusable parameterized types
  • Union types: string | number
  • Type inference: compiler deduces types automatically
  • Strict mode: maximum type safety

TypeScript in the ecosystem

  • React: typed JSX, typed props
  • Next.js: native support
  • AWS CDK: typed infrastructure
  • Node.js: typed backend

Configuring strict

Strict mode enables all type checks. It is the recommended configuration for new projects:

{
  "compilerOptions": {
    "strict": true,
    "target": "ES2022",
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "esModuleInterop": true,
    "skipLibCheck": true,
    "outDir": "dist"
  }
}

Individual flags that strict enables:

FlagWhat it prevents
strictNullChecksAccessing null/undefined without checking
noImplicitAnyVariables without explicit or inferred type
strictFunctionTypesIncorrect contravariant function parameters
strictPropertyInitializationUninitialized class properties
noImplicitThisUsing this without a known type

When NOT to use TypeScript

  • One-off scripts (bash or Python are faster)
  • Throwaway prototypes where iteration speed matters more than correctness
  • Projects where the team has no experience with static types (the learning curve is real)

Why it matters

TypeScript turns runtime errors into compile-time errors. In projects of any size, the type system acts as living documentation, enables safe refactoring, and reduces the most common category of bugs: type errors.

References

Concepts