Compiler Options
There are 100+ compiler options. You only need a handful — but the right handful matters a lot.
The output shape
| Option | Default / typical |
|---|---|
target | "ES2022" — JS version of the emitted code. |
module | "NodeNext" / "Bundler" |
outDir | Where compiled JS goes. |
rootDir | Where source lives. |
declaration | Emit .d.ts files (for libraries). |
sourceMap | Emit .js.map for debugging. |
noEmit | Type-check only. Common in CI. |
Strictness — turn these ON
| Option | Catches |
|---|---|
strict | Enables every check below at once. |
noImplicitAny | "Couldn't infer — please annotate." |
strictNullChecks | null / undefined slipping through. |
strictFunctionTypes | Unsafe variance in function types. |
strictBindCallApply | Wrong args to bind/call/apply. |
noImplicitThis | this typed as any. |
useUnknownInCatchVariables | catch (e) — e is unknown. |
noUncheckedIndexedAccess | arr[i] returns T | undefined. |
exactOptionalPropertyTypes | Disallows passing undefined where ?: was meant for "absent". |
noImplicitReturns | Function paths that forget to return. |
Module & interop
| Option | Effect |
|---|---|
esModuleInterop | Cleaner import x from 'cjs-module'. |
resolveJsonModule | Import .json as typed data. |
verbatimModuleSyntax | Require import type for type-only imports. |
forceConsistentCasingInFileNames | Case-sensitive imports (matches Linux). |
Performance
| Option | What it does |
|---|---|
skipLibCheck | Don't type-check declaration files in node_modules. |
incremental | Cache type info between runs. |
composite | Required 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
Eight characters; starts with --.
Discussion
Loading…