iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

Compiler Options

There are 100+ compiler options. You only need a handful — but the right handful matters a lot.

The output shape

OptionDefault / typical
target"ES2022" — JS version of the emitted code.
module"NodeNext" / "Bundler"
outDirWhere compiled JS goes.
rootDirWhere source lives.
declarationEmit .d.ts files (for libraries).
sourceMapEmit .js.map for debugging.
noEmitType-check only. Common in CI.

Strictness — turn these ON

OptionCatches
strictEnables every check below at once.
noImplicitAny"Couldn't infer — please annotate."
strictNullChecksnull / undefined slipping through.
strictFunctionTypesUnsafe variance in function types.
strictBindCallApplyWrong args to bind/call/apply.
noImplicitThisthis typed as any.
useUnknownInCatchVariablescatch (e) — e is unknown.
noUncheckedIndexedAccessarr[i] returns T | undefined.
exactOptionalPropertyTypesDisallows passing undefined where ?: was meant for "absent".
noImplicitReturnsFunction paths that forget to return.

Module & interop

OptionEffect
esModuleInteropCleaner import x from 'cjs-module'.
resolveJsonModuleImport .json as typed data.
verbatimModuleSyntaxRequire import type for type-only imports.
forceConsistentCasingInFileNamesCase-sensitive imports (matches Linux).

Performance

OptionWhat it does
skipLibCheckDon't type-check declaration files in node_modules.
incrementalCache type info between runs.
compositeRequired for project references.
Tip: Set "strict": true on day one and keep it on. Adding strictness later means fixing a hundred files at once; starting strict means each new file gets it right.

Example

Example
// Common compiler options:
//   target         — JS version to emit (ES2022, ESNext, …)
//   module         — module system (NodeNext, ESNext, CommonJS)
//   strict         — all strict flags on
//   noUncheckedIndexedAccess — safer arr[i]
//   exactOptionalPropertyTypes — pickier optionals
//   outDir / rootDir  — where files go / come from
console.log('cli: tsc --noEmit  to type-check without output');
Try it Yourself »

Exercise

Option for "type-check only, no output".

tsc

Test yourself

Q1. Type-check only (no JS output) with…
Q2. Skip checking node_modules .d.ts with…
Q3. arr[i] being T | undefined is from…

Discussion

Loading…