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```ts twoslash// @noImplicitAny: false// @target: esnext// @lib: esnext// This suppose to throw an error,// but it won't because we disabled noImplicitAny.const fn = a => a + 1```Available Compiler Flags
Section titled “Available Compiler Flags”@allowJs
Section titled “@allowJs”Allow JavaScript files to be a part of your program. Use the checkJS option to get errors from these files
Example Usage
// @allowJs@allowSyntheticDefaultImports
Section titled “@allowSyntheticDefaultImports”Allow ‘import x from y’ when a module doesn’t have a default export.
*Example Usage
// @allowSyntheticDefaultImports@allowUmdGlobalAccess
Section titled “@allowUmdGlobalAccess”Allow accessing UMD globals from modules.
Example Usage
// @allowUmdGlobalAccess@allowUnreachableCode
Section titled “@allowUnreachableCode”Disable error reporting for unreachable code.
Example Usage
// @allowUnreachableCode@allowUnusedLabels
Section titled “@allowUnusedLabels”Disable error reporting for unused labels.
Example Usage
// @allowUnusedLabels@alwaysStrict
Section titled “@alwaysStrict”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@baseUrl
Section titled “@baseUrl”Specify the base directory to resolve non-relative module names.
Example Usage
// @baseUrl@charset
Section titled “@charset”No longer supported. In early versions, manually set the text encoding for reading files.
Example Usage
// @charset@checkJs
Section titled “@checkJs”Enable error reporting in type-checked JavaScript files.
Example Usage
// @checkJs@composite
Section titled “@composite”Enable constraints that allow a TypeScript project to be used with project references.
Example Usage
// @composite@declaration
Section titled “@declaration”Generate .d.ts files from TypeScript and JavaScript files in your project.
Example Usage
// @declaration@declarationDir
Section titled “@declarationDir”Specify the output directory for generated declaration files.
Example Usage
// @declarationDir@declarationMap
Section titled “@declarationMap”Create sourcemaps for d.ts files.
Example Usage
// @declarationMap@diagnostics
Section titled “@diagnostics”Output compiler performance information after building.
Example Usage
// @diagnostics@disableReferencedProjectLoad
Section titled “@disableReferencedProjectLoad”Reduce the number of projects loaded automatically by TypeScript.
Example Usage
// @disableReferencedProjectLoad@disableSizeLimit
Section titled “@disableSizeLimit”Remove the 20mb cap on total source code size for JavaScript files in the TypeScript language server.
Example Usage
// @disableSizeLimit@disableSolutionSearching
Section titled “@disableSolutionSearching”Opt a project out of multi-project reference checking when editing.
Example Usage
// @disableSolutionSearching@disableSourceOfProjectReferenceRedirect
Section titled “@disableSourceOfProjectReferenceRedirect”Disable preferring source files instead of declaration files when referencing composite projects.
Example Usage
// @disableSourceOfProjectReferenceRedirect@downlevelIteration
Section titled “@downlevelIteration”Emit more compliant, but verbose and less performant JavaScript for iteration.
Example Usage
// @downlevelIteration@emitBOM
Section titled “@emitBOM”Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files.
Example Usage
// @emitBOM@emitDeclarationOnly
Section titled “@emitDeclarationOnly”Only output d.ts files and not JavaScript files.
Example Usage
// @emitDeclarationOnly@emitDecoratorMetadata
Section titled “@emitDecoratorMetadata”Emit design-type metadata for decorated declarations in source files.
Example Usage
// @emitDecoratorMetadata@esModuleInterop
Section titled “@esModuleInterop”Emit additional JavaScript to ease support for importing CommonJS modules. This enables allowSyntheticDefaultImports for type compatibility.
Example Usage
// @esModuleInterop@exactOptionalPropertyTypes
Section titled “@exactOptionalPropertyTypes”Interpret optional property types as written, rather than adding ‘undefined’.
Example Usage
// @exactOptionalPropertyTypes@experimentalDecorators
Section titled “@experimentalDecorators”Enable experimental support for TC39 stage 2 draft decorators.
Example Usage
// @experimentalDecorators@explainFiles
Section titled “@explainFiles”Print files read during the compilation including why it was included.
Example Usage
// @explainFiles@extendedDiagnostics
Section titled “@extendedDiagnostics”Output more detailed compiler performance information after building.
Example Usage
// @extendedDiagnostics@forceConsistentCasingInFileNames
Section titled “@forceConsistentCasingInFileNames”Ensure that casing is correct in imports.
Example Usage
// @forceConsistentCasingInFileNames@generateCpuProfile
Section titled “@generateCpuProfile”Emit a v8 CPU profile of the compiler run for debugging.
Example Usage
// @generateCpuProfile@importHelpers
Section titled “@importHelpers”Allow importing helper functions from tslib once per project, instead of including them per-file.
Example Usage
// @importHelpers@importsNotUsedAsValues
Section titled “@importsNotUsedAsValues”Specify emit/checking behavior for imports that are only used for types.
Example Usage
// @importsNotUsedAsValues@incremental
Section titled “@incremental”Enable incremental compilation.
Example Usage
// @incremental@inlineSourceMap
Section titled “@inlineSourceMap”Include sourcemap files inside the emitted JavaScript.
Example Usage
// @inlineSourceMap@inlineSources
Section titled “@inlineSources”Include source code in the sourcemaps inside the emitted JavaScript.
Example Usage
// @inlineSources@isolatedModules
Section titled “@isolatedModules”Ensure that each file can be safely transpiled without relying on other imports.
Example Usage
// @isolatedModulesSpecify what JSX code is generated.
Example Usage
// @jsx@jsxFactory
Section titled “@jsxFactory”Specify the JSX factory function used when targeting React JSX emit, e.g. ‘React.createElement’ or ‘h’.
Example Usage
// @jsxFactory@jsxFragmentFactory
Section titled “@jsxFragmentFactory”Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. ‘React.Fragment’ or ‘Fragment’.
Example Usage
// @jsxFragmentFactory@jsxImportSource
Section titled “@jsxImportSource”Specify module specifier used to import the JSX factory functions when using jsx: react-jsx*.
Example Usage
// @jsxImportSource@keyofStringsOnly
Section titled “@keyofStringsOnly”Make keyof only return strings instead of string, numbers or symbols. Legacy option.
Example Usage
// @keyofStringsOnlySpecify a set of bundled library declaration files that describe the target runtime environment.
Example Usage
// @lib@listEmittedFiles
Section titled “@listEmittedFiles”Print the names of emitted files after a compilation.
Example Usage
// @listEmittedFiles@listFiles
Section titled “@listFiles”Print all of the files read during the compilation.
Example Usage
// @listFiles@mapRoot
Section titled “@mapRoot”Specify the location where debugger should locate map files instead of generated locations.
Example Usage
// @mapRoot@maxNodeModuleJsDepth
Section titled “@maxNodeModuleJsDepth”Specify the maximum folder depth used for checking JavaScript files from node_modules. Only applicable with allowJs.
Example Usage
// @maxNodeModuleJsDepth@module
Section titled “@module”Specify what module code is generated.
Example Usage
// @module@moduleResolution
Section titled “@moduleResolution”Specify how TypeScript looks up a file from a given module specifier.
Example Usage
// @moduleResolution@newLine
Section titled “@newLine”Set the newline character for emitting files.
Example Usage
// @newLine@noEmit
Section titled “@noEmit”Disable emitting file from a compilation.
Example Usage
// @noEmit@noEmitHelpers
Section titled “@noEmitHelpers”Disable generating custom helper functions like __extends in compiled output.
Example Usage
// @noEmitHelpers@noEmitOnError
Section titled “@noEmitOnError”Disable emitting files if any type checking errors are reported.
Example Usage
// @noEmitOnError@noErrorTruncation
Section titled “@noErrorTruncation”Disable truncating types in error messages.
Example Usage
// @noErrorTruncation@noFallthroughCasesInSwitch
Section titled “@noFallthroughCasesInSwitch”Enable error reporting for fallthrough cases in switch statements.
Example Usage
// @noFallthroughCasesInSwitch@noImplicitAny
Section titled “@noImplicitAny”Enable error reporting for expressions and declarations with an implied any type.
Example Usage
// @noImplicitAny@noImplicitOverride
Section titled “@noImplicitOverride”Add undefined to a type when accessed using an index.
Example Usage
// @noImplicitOverride@noImplicitReturns
Section titled “@noImplicitReturns”Enable error reporting for codepaths that do not explicitly return in a function.
Example Usage
// @noImplicitReturns@noImplicitThis
Section titled “@noImplicitThis”Enable error reporting when this is given the type any.
Example Usage
// @noImplicitThis@noImplicitUseStrict
Section titled “@noImplicitUseStrict”Disable adding ‘use strict’ directives in emitted JavaScript files.
Example Usage
// @noImplicitUseStrict@noLib
Section titled “@noLib”Disable including any library files, including the default lib.d.ts.
Example Usage
// @noLib@noPropertyAccessFromIndexSignature
Section titled “@noPropertyAccessFromIndexSignature”Enforces using indexed accessors for keys declared using an indexed type.
Example Usage
// @noPropertyAccessFromIndexSignature@noResolve
Section titled “@noResolve”Disallow imports, requires or “s from expanding the number of files TypeScript should add to a project.
Example Usage
// @noResolve@noStrictGenericChecks
Section titled “@noStrictGenericChecks”Disable strict checking of generic signatures in function types.
Example Usage
// @noStrictGenericChecks@noUncheckedIndexedAccess
Section titled “@noUncheckedIndexedAccess”Include ‘undefined’ in index signature results.
Example Usage
// @noUncheckedIndexedAccess@noUnusedLocals
Section titled “@noUnusedLocals”Enable error reporting when a local variables aren’t read.
Example Usage
// @noUnusedLocals@noUnusedParameters
Section titled “@noUnusedParameters”Raise an error when a function parameter isn’t read.
Example Usage
// @noUnusedParametersDeprecated setting. Use outFile instead.
Example Usage
// @out@outDir
Section titled “@outDir”Specify an output folder for all emitted files.
Example Usage
// @outDir@outFile
Section titled “@outFile”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@paths
Section titled “@paths”Specify a set of entries that re-map imports to additional lookup locations.
Example Usage
// @paths@plugins
Section titled “@plugins”List of language service plugins.
Example Usage
// @plugins@preserveConstEnums
Section titled “@preserveConstEnums”Disable erasing const enum declarations in generated code.
Example Usage
// @preserveConstEnums@preserveSymlinks
Section titled “@preserveSymlinks”Disable resolving symlinks to their realpath. This correlates to the same flag in node.
Example Usage
// @preserveSymlinks@preserveWatchOutput
Section titled “@preserveWatchOutput”Disable wiping the console in watch mode.
Example Usage
// @preserveWatchOutput@pretty
Section titled “@pretty”Enable color and formatting in output to make compiler errors easier to read.
Example Usage
// @pretty@reactNamespace
Section titled “@reactNamespace”Specify the object invoked for createElement. This only applies when targeting react JSX emit.
Example Usage
// @reactNamespace@removeComments
Section titled “@removeComments”Disable emitting comments.
Example Usage
// @removeComments@resolveJsonModule
Section titled “@resolveJsonModule”Enable importing .json files.
Example Usage
// @resolveJsonModule@rootDir
Section titled “@rootDir”Specify the root folder within your source files.
Example Usage
// @rootDir@rootDirs
Section titled “@rootDirs”Allow multiple folders to be treated as one when resolving modules.
Example Usage
// @rootDirs@skipDefaultLibCheck
Section titled “@skipDefaultLibCheck”Skip type checking .d.ts files that are included with TypeScript.
Example Usage
// @skipDefaultLibCheck@skipLibCheck
Section titled “@skipLibCheck”Skip type checking all .d.ts files.
Example Usage
// @skipLibCheck@sourceMap
Section titled “@sourceMap”Create source map files for emitted JavaScript files.
Example Usage
// @sourceMap@sourceRoot
Section titled “@sourceRoot”Specify the root path for debuggers to find the reference source code.
Example Usage
// @sourceRoot@strict
Section titled “@strict”Enable all strict type-checking options.
Example Usage
// @strict@strictBindCallApply
Section titled “@strictBindCallApply”Check that the arguments for bind, call, and apply methods match the original function.
Example Usage
// @strictBindCallApply@strictFunctionTypes
Section titled “@strictFunctionTypes”When assigning functions, check to ensure parameters and the return values are subtype-compatible.
Example Usage
// @strictFunctionTypes@strictNullChecks
Section titled “@strictNullChecks”When type checking, take into account null and undefined.
Example Usage
// @strictNullChecks@strictPropertyInitialization
Section titled “@strictPropertyInitialization”Check for class properties that are declared but not set in the constructor.
Example Usage
// @strictPropertyInitialization@stripInternal
Section titled “@stripInternal”Disable emitting declarations that have @internal in their JSDoc comments.
Example Usage
// @stripInternal@suppressExcessPropertyErrors
Section titled “@suppressExcessPropertyErrors”Disable reporting of excess property errors during the creation of object literals.
Example Usage
// @suppressExcessPropertyErrors@suppressImplicitAnyIndexErrors
Section titled “@suppressImplicitAnyIndexErrors”Suppress noImplicitAny errors when indexing objects that lack index signatures.
Example Usage
// @suppressImplicitAnyIndexErrors@target
Section titled “@target”Set the JavaScript language version for emitted JavaScript and include compatible library declarations.
Example Usage
// @target@traceResolution
Section titled “@traceResolution”Log paths used during the moduleResolution process.
Example Usage
// @traceResolution@tsBuildInfoFile
Section titled “@tsBuildInfoFile”Specify the folder for .tsbuildinfo incremental compilation files.
Example Usage
// @tsBuildInfoFile@typeRoots
Section titled “@typeRoots”Specify multiple folders that act like ./node_modules/@types.
Example Usage
// @typeRoots@types
Section titled “@types”Specify type package names to be included without being referenced in a source file.
Example Usage
// @types@useDefineForClassFields
Section titled “@useDefineForClassFields”Emit ECMAScript-standard-compliant class fields.
Example Usage
// @useDefineForClassFields@useUnknownInCatchVariables
Section titled “@useUnknownInCatchVariables”Type catch clause variables as ‘unknown’ instead of ‘any’.
Example Usage
// @useUnknownInCatchVariables