A TypeScript file does not have one fixed meaning. The options in
tsconfig.json decide
which programs are valid and what JavaScript is written. This page covers the options that
change the result for a given file. The
TSConfig reference lists all of them.
Defaults here are those of TypeScript 7.0.
Strictness
strict switches on a family of checks, and is true by default
since 6.0. Each member can also be set separately, and defaults to the value of
strict.
| Option | Effect |
|---|---|
noImplicitAny | An inferred any is an error |
noImplicitThis | Using this with an unknown type is an error |
strictNullChecks | null and undefined are their own types |
strictFunctionTypes | Parameters of function types are checked contravariantly; methods stay bivariant |
strictBindCallApply | bind, call and apply are checked against the function |
strictPropertyInitialization | Class fields must be initialised |
strictBuiltinIteratorReturn | Built-in iterators have undefined, not any, as the type of their return value |
useUnknownInCatchVariables | A catch variable is unknown, not any |
alwaysStrict used to control whether files were parsed in strict mode. All
code is now strict, and false is an error in 7.0.
Other checks
These are not part of strict, and are off by default.
| Option | Effect |
|---|---|
exactOptionalPropertyTypes | An optional property cannot be assigned undefined unless its type says so |
noUncheckedIndexedAccess | Reading through an index signature or an array adds undefined to the type |
noPropertyAccessFromIndexSignature | Index-signature keys must be read with o["k"] |
noImplicitOverride | An override must use override |
noImplicitReturns | Every code path must return a value |
noFallthroughCasesInSwitch | A non-empty case must end with a break or similar |
noUnusedLocals, noUnusedParameters | Unused names are errors |
allowUnreachableCode, allowUnusedLabels | Unset: editor warnings. false: errors. true: ignored |
noUncheckedSideEffectImports | A side-effect import must resolve. On by default since 6.0 |
interface Options { port?: number }
const o: Options = { port: undefined }; // error with exactOptionalPropertyTypes
const list = [1];
const n: number = list[0]; // error with noUncheckedIndexedAccess
Language and environment
| Option | Effect |
|---|---|
target | The JavaScript version written, from es2015 to esnext. Default es2025. Also sets the default lib |
lib | Which standard library files to load |
noLib | Loads no standard library |
jsx | How JSX is written, and whether it is allowed |
experimentalDecorators | Uses legacy decorators |
emitDecoratorMetadata | Writes type metadata for legacy decorators |
useDefineForClassFields | Class fields are defined by the ECMAScript rules. On for target ES2022 and later |
moduleDetection | Which files are modules |
Modules
| Option | Effect |
|---|---|
module | The output format. Default esnext |
moduleResolution | How specifiers are found |
paths, rootDirs, customConditions | Adjust resolution for type checking |
types, typeRoots | Which @types packages are global. types defaults to [] |
allowImportingTsExtensions, rewriteRelativeImportExtensions | Imports ending in .ts |
resolveJsonModule | Allows importing .json |
allowArbitraryExtensions | Allows importing other file types with a .d.x.ts beside them |
allowJs, checkJs | Allow and check JavaScript files |
Interop constraints
These restrict the code to what can be handled in a particular way. They are off by default.
| Option | Effect |
|---|---|
verbatimModuleSyntax | Keeps every import and export without type, so no elision. A type imported without type is an error. Implies isolatedModules (5.0) |
isolatedModules | Rejects code that cannot be compiled one file at a time, such as re-exporting a type without export type, or using an ambient const enum |
isolatedDeclarations | Requires annotations on exports (5.5) |
erasableSyntaxOnly | Rejects constructs that generate code (5.8) |
forceConsistentCasingInFileNames | Import paths must match the file’s case. On by default |
// With verbatimModuleSyntax
import { User } from "./user.js"; // error: User is a type, use import type
import type { User } from "./user.js"; // fine, and removed from the output
import { type User, save } from "./user.js"; // becomes: import { save } from "./user.js";
// With isolatedModules
import { User } from "./user.js";
export { User }; // error: use export type
Emit
| Option | Effect |
|---|---|
noEmit | Checks only |
noEmitOnError | Writes nothing if there are errors |
noCheck | Writes output without a full type check (5.6) |
outDir, rootDir | Where output goes. rootDir defaults to the folder of tsconfig.json |
declaration, declarationMap | Writes declaration files |
sourceMap, inlineSourceMap, inlineSources | Writes source maps, separately or in the JavaScript |
removeComments | Drops comments from the output |
preserveConstEnums | Writes const enum objects as well as inlining them |
importHelpers | Imports helpers from the tslib package, not writing them in each file |
noEmitHelpers | Writes no helpers at all |
newLine, emitBOM | Line endings and a byte order mark in the output |
Changes in 6.0 and 7.0
6.0 changed several defaults and deprecated many older settings, and 7.0, the native compiler written in Go, removed them.
| Setting | Before 6.0 | Since 6.0 |
|---|---|---|
strict | false | true |
module | Depended on target | esnext |
target | An old ECMAScript version | A recent version: es2025 in 7.0 |
types | Every @types package | [] |
rootDir | Computed from the inputs | The folder of tsconfig.json |
noUncheckedSideEffectImports | false | true |
libReplacement | true | false |
Errors in 7.0, removed or no longer settable:
target: es5anddownlevelIteration.moduleResolution: node(also callednode10) andclassic.module: amd,umd,systemandnone.baseUrl.pathsentries are relative to the project.esModuleInteropandallowSyntheticDefaultImportsset tofalse, andalwaysStrictset tofalse.- The
modulekeyword on a namespace, andasserton an import. - Files named on the command line in a folder with a
tsconfig.json, without--ignoreConfig.