Skip to content

Overriding TSCompiler Flags

Using the // @name and // @name: value notations to override the compiler options for TypeScript language features and handbook options for TwoSlash. The notations will be removed from the output.

// This suppose to throw an error,
// but it won't because we disabled noImplicitAny.
const
const fn: (a: any) => any
fn
=
a: any
a
=>
a: any
a
+ 1

Allow JavaScript files to be a part of your program. Use the checkJS option to get errors from these files

Example Usage

// @allowJs

Allow ‘import x from y’ when a module doesn’t have a default export.

*Example Usage

// @allowSyntheticDefaultImports

Allow accessing UMD globals from modules.

Example Usage

// @allowUmdGlobalAccess

Disable error reporting for unreachable code.

Example Usage

// @allowUnreachableCode

Disable error reporting for unused labels.

Example Usage

// @allowUnusedLabels

Ensure ‘use strict’ is always emitted.

Example Usage

// @alwaysStrict

@assumeChangesOnlyAffectDirectDependencies

Section titled “@assumeChangesOnlyAffectDirectDependencies”

Have recompiles in projects that use incremental and watch mode assume that changes within a file will only affect files directly depending on it.

Example Usage

// @assumeChangesOnlyAffectDirectDependencies

Specify the base directory to resolve non-relative module names.

Example Usage

// @baseUrl

No longer supported. In early versions, manually set the text encoding for reading files.

Example Usage

// @charset

Enable error reporting in type-checked JavaScript files.

Example Usage

// @checkJs

Enable constraints that allow a TypeScript project to be used with project references.

Example Usage

// @composite

Generate .d.ts files from TypeScript and JavaScript files in your project.

Example Usage

// @declaration

Specify the output directory for generated declaration files.

Example Usage

// @declarationDir

Create sourcemaps for d.ts files.

Example Usage

// @declarationMap

Output compiler performance information after building.

Example Usage

// @diagnostics

Reduce the number of projects loaded automatically by TypeScript.

Example Usage

// @disableReferencedProjectLoad

Remove the 20mb cap on total source code size for JavaScript files in the TypeScript language server.

Example Usage

// @disableSizeLimit

Opt a project out of multi-project reference checking when editing.

Example Usage

// @disableSolutionSearching

Disable preferring source files instead of declaration files when referencing composite projects.

Example Usage

// @disableSourceOfProjectReferenceRedirect

Emit more compliant, but verbose and less performant JavaScript for iteration.

Example Usage

// @downlevelIteration

Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files.

Example Usage

// @emitBOM

Only output d.ts files and not JavaScript files.

Example Usage

// @emitDeclarationOnly

Emit design-type metadata for decorated declarations in source files.

Example Usage

// @emitDecoratorMetadata

Emit additional JavaScript to ease support for importing CommonJS modules. This enables allowSyntheticDefaultImports for type compatibility.

Example Usage

// @esModuleInterop

Interpret optional property types as written, rather than adding ‘undefined’.

Example Usage

// @exactOptionalPropertyTypes

Enable experimental support for TC39 stage 2 draft decorators.

Example Usage

// @experimentalDecorators

Print files read during the compilation including why it was included.

Example Usage

// @explainFiles

Output more detailed compiler performance information after building.

Example Usage

// @extendedDiagnostics

Ensure that casing is correct in imports.

Example Usage

// @forceConsistentCasingInFileNames

Emit a v8 CPU profile of the compiler run for debugging.

Example Usage

// @generateCpuProfile

Allow importing helper functions from tslib once per project, instead of including them per-file.

Example Usage

// @importHelpers

Specify emit/checking behavior for imports that are only used for types.

Example Usage

// @importsNotUsedAsValues

Enable incremental compilation.

Example Usage

// @incremental

Include sourcemap files inside the emitted JavaScript.

Example Usage

// @inlineSourceMap

Include source code in the sourcemaps inside the emitted JavaScript.

Example Usage

// @inlineSources

Ensure that each file can be safely transpiled without relying on other imports.

Example Usage

// @isolatedModules

Specify what JSX code is generated.

Example Usage

// @jsx

Specify the JSX factory function used when targeting React JSX emit, e.g. ‘React.createElement’ or ‘h’.

Example Usage

// @jsxFactory

Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. ‘React.Fragment’ or ‘Fragment’.

Example Usage

// @jsxFragmentFactory

Specify module specifier used to import the JSX factory functions when using jsx: react-jsx*.

Example Usage

// @jsxImportSource

Make keyof only return strings instead of string, numbers or symbols. Legacy option.

Example Usage

// @keyofStringsOnly

Specify a set of bundled library declaration files that describe the target runtime environment.

Example Usage

// @lib

Print the names of emitted files after a compilation.

Example Usage

// @listEmittedFiles

Print all of the files read during the compilation.

Example Usage

// @listFiles

Specify the location where debugger should locate map files instead of generated locations.

Example Usage

// @mapRoot

Specify the maximum folder depth used for checking JavaScript files from node_modules. Only applicable with allowJs.

Example Usage

// @maxNodeModuleJsDepth

Specify what module code is generated.

Example Usage

// @module

Specify how TypeScript looks up a file from a given module specifier.

Example Usage

// @moduleResolution

Set the newline character for emitting files.

Example Usage

// @newLine

Disable emitting file from a compilation.

Example Usage

// @noEmit

Disable generating custom helper functions like __extends in compiled output.

Example Usage

// @noEmitHelpers

Disable emitting files if any type checking errors are reported.

Example Usage

// @noEmitOnError

Disable truncating types in error messages.

Example Usage

// @noErrorTruncation

Enable error reporting for fallthrough cases in switch statements.

Example Usage

// @noFallthroughCasesInSwitch

Enable error reporting for expressions and declarations with an implied any type.

Example Usage

// @noImplicitAny

Add undefined to a type when accessed using an index.

Example Usage

// @noImplicitOverride

Enable error reporting for codepaths that do not explicitly return in a function.

Example Usage

// @noImplicitReturns

Enable error reporting when this is given the type any.

Example Usage

// @noImplicitThis

Disable adding ‘use strict’ directives in emitted JavaScript files.

Example Usage

// @noImplicitUseStrict

Disable including any library files, including the default lib.d.ts.

Example Usage

// @noLib

Enforces using indexed accessors for keys declared using an indexed type.

Example Usage

// @noPropertyAccessFromIndexSignature

Disallow imports, requires or “s from expanding the number of files TypeScript should add to a project.

Example Usage

// @noResolve

Disable strict checking of generic signatures in function types.

Example Usage

// @noStrictGenericChecks

Include ‘undefined’ in index signature results.

Example Usage

// @noUncheckedIndexedAccess

Enable error reporting when a local variables aren’t read.

Example Usage

// @noUnusedLocals

Raise an error when a function parameter isn’t read.

Example Usage

// @noUnusedParameters

Deprecated setting. Use outFile instead.

Example Usage

// @out

Specify an output folder for all emitted files.

Example Usage

// @outDir

Specify a file that bundles all outputs into one JavaScript file. If declaration is true, also designates a file that bundles all .d.ts output.

Example Usage

// @outFile

Specify a set of entries that re-map imports to additional lookup locations.

Example Usage

// @paths

List of language service plugins.

Example Usage

// @plugins

Disable erasing const enum declarations in generated code.

Example Usage

// @preserveConstEnums

Disable resolving symlinks to their realpath. This correlates to the same flag in node.

Example Usage

// @preserveSymlinks

Disable wiping the console in watch mode.

Example Usage

// @preserveWatchOutput

Enable color and formatting in output to make compiler errors easier to read.

Example Usage

// @pretty

Specify the object invoked for createElement. This only applies when targeting react JSX emit.

Example Usage

// @reactNamespace

Disable emitting comments.

Example Usage

// @removeComments

Enable importing .json files.

Example Usage

// @resolveJsonModule

Specify the root folder within your source files.

Example Usage

// @rootDir

Allow multiple folders to be treated as one when resolving modules.

Example Usage

// @rootDirs

Skip type checking .d.ts files that are included with TypeScript.

Example Usage

// @skipDefaultLibCheck

Skip type checking all .d.ts files.

Example Usage

// @skipLibCheck

Create source map files for emitted JavaScript files.

Example Usage

// @sourceMap

Specify the root path for debuggers to find the reference source code.

Example Usage

// @sourceRoot

Enable all strict type-checking options.

Example Usage

// @strict

Check that the arguments for bind, call, and apply methods match the original function.

Example Usage

// @strictBindCallApply

When assigning functions, check to ensure parameters and the return values are subtype-compatible.

Example Usage

// @strictFunctionTypes

When type checking, take into account null and undefined.

Example Usage

// @strictNullChecks

Check for class properties that are declared but not set in the constructor.

Example Usage

// @strictPropertyInitialization

Disable emitting declarations that have @internal in their JSDoc comments.

Example Usage

// @stripInternal

Disable reporting of excess property errors during the creation of object literals.

Example Usage

// @suppressExcessPropertyErrors

Suppress noImplicitAny errors when indexing objects that lack index signatures.

Example Usage

// @suppressImplicitAnyIndexErrors

Set the JavaScript language version for emitted JavaScript and include compatible library declarations.

Example Usage

// @target

Log paths used during the moduleResolution process.

Example Usage

// @traceResolution

Specify the folder for .tsbuildinfo incremental compilation files.

Example Usage

// @tsBuildInfoFile

Specify multiple folders that act like ./node_modules/@types.

Example Usage

// @typeRoots

Specify type package names to be included without being referenced in a source file.

Example Usage

// @types

Emit ECMAScript-standard-compliant class fields.

Example Usage

// @useDefineForClassFields

Type catch clause variables as ‘unknown’ instead of ‘any’.

Example Usage

// @useUnknownInCatchVariables