Study notes · 10% of the exam

Compiler Options and Strictness

Know what tsc checks, what it emits and what it never does at runtime. Then know the handful of options that change type safety, module output and build behaviour, including the defaults that changed in TypeScript 6.0.

Key points

  1. 1

    Types are erased: tsc adds no runtime checks, emits even on errors unless noEmitOnError is set, and never polyfills APIs.

  2. 2

    strict (on by default since TypeScript 6.0) bundles strictNullChecks, noImplicitAny, strictFunctionTypes, strictBindCallApply, strictPropertyInitialization, noImplicitThis, useUnknownInCatchVariables and alwaysStrict. noUncheckedIndexedAccess and exactOptionalPropertyTypes are separate opt-ins.

  3. 3

    target controls emitted syntax; lib controls which API types exist. Raising lib without a polyfill only hides runtime crashes.

  4. 4

    Under module: "nodenext", relative imports need the runtime extension (./b.js). paths never rewrites emitted imports.

  5. 5

    isolatedModules, verbatimModuleSyntax and erasableSyntaxOnly make tsc report code that single-file transpilers or Node's type stripping would get wrong.

  6. 6

    Project references need composite and tsc -b. Plain tsc -p checks against whatever .d.ts files a referenced project last emitted.

  7. 7

    TypeScript 6.0 defaults types to [], enables noUncheckedSideEffectImports, ties rootDir to the tsconfig folder, and deprecates baseUrl, node10 resolution, ES5 targets and outFile.

Common traps

  • exclude does not keep a file out of the program if another file imports it.

  • skipLibCheck also skips your own hand-written .d.ts files.

  • Deleting dist/ but keeping a .tsbuildinfo stored elsewhere makes the next incremental build emit nothing.

Test yourself on Compiler Options and Strictness

Ten questions, with the answer and explanation after each one.