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.
```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
// @allowJsAllow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files..
// @allowSyntheticDefaultImportsAllow 'import x from y' when a module doesn't have a default export..
// @allowUmdGlobalAccessAllow accessing UMD globals from modules..
// @allowUnreachableCodeDisable error reporting for unreachable code..
// @allowUnusedLabelsDisable error reporting for unused labels..
// @alwaysStrictEnsure 'use strict' is always emitted..
// @assumeChangesOnlyAffectDirectDependenciesHave recompiles in projects that use `incremental` and `watch` mode assume that changes within a file will only affect files directly depending on it..
// @baseUrlSpecify the base directory to resolve non-relative module names..
// @charsetNo longer supported. In early versions, manually set the text encoding for reading files..
// @checkJsEnable error reporting in type-checked JavaScript files..
// @compositeEnable constraints that allow a TypeScript project to be used with project references..
// @declarationGenerate .d.ts files from TypeScript and JavaScript files in your project..
// @declarationDirSpecify the output directory for generated declaration files..
// @declarationMapCreate sourcemaps for d.ts files..
// @diagnosticsOutput compiler performance information after building..
// @disableReferencedProjectLoadReduce the number of projects loaded automatically by TypeScript..
// @disableSizeLimitRemove the 20mb cap on total source code size for JavaScript files in the TypeScript language server..
// @disableSolutionSearchingOpt a project out of multi-project reference checking when editing..
// @disableSourceOfProjectReferenceRedirectDisable preferring source files instead of declaration files when referencing composite projects.
// @downlevelIterationEmit more compliant, but verbose and less performant JavaScript for iteration..
// @emitBOMEmit a UTF-8 Byte Order Mark (BOM) in the beginning of output files..
// @emitDeclarationOnlyOnly output d.ts files and not JavaScript files..
// @emitDecoratorMetadataEmit design-type metadata for decorated declarations in source files..
// @esModuleInteropEmit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility..
// @exactOptionalPropertyTypesInterpret optional property types as written, rather than adding 'undefined'..
// @experimentalDecoratorsEnable experimental support for TC39 stage 2 draft decorators..
// @explainFilesPrint files read during the compilation including why it was included..
// @extendedDiagnosticsOutput more detailed compiler performance information after building..
// @forceConsistentCasingInFileNamesEnsure that casing is correct in imports..
// @generateCpuProfileEmit a v8 CPU profile of the compiler run for debugging..
// @importHelpersAllow importing helper functions from tslib once per project, instead of including them per-file..
// @importsNotUsedAsValuesSpecify emit/checking behavior for imports that are only used for types.
// @incrementalEnable incremental compilation.
// @inlineSourceMapInclude sourcemap files inside the emitted JavaScript..
// @inlineSourcesInclude source code in the sourcemaps inside the emitted JavaScript..
// @isolatedModulesEnsure that each file can be safely transpiled without relying on other imports..
// @jsxSpecify what JSX code is generated..
// @jsxFactorySpecify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'.
// @jsxFragmentFactorySpecify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'..
// @jsxImportSourceSpecify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.`.
// @keyofStringsOnlyMake keyof only return strings instead of string, numbers or symbols. Legacy option..
// @libSpecify a set of bundled library declaration files that describe the target runtime environment..
// @listEmittedFilesPrint the names of emitted files after a compilation..
// @listFilesPrint all of the files read during the compilation..
// @mapRootSpecify the location where debugger should locate map files instead of generated locations..
// @maxNodeModuleJsDepthSpecify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`..
// @moduleSpecify what module code is generated..
// @moduleResolutionSpecify how TypeScript looks up a file from a given module specifier..
// @newLineSet the newline character for emitting files..
// @noEmitDisable emitting file from a compilation..
// @noEmitHelpersDisable generating custom helper functions like `__extends` in compiled output..
// @noEmitOnErrorDisable emitting files if any type checking errors are reported..
// @noErrorTruncationDisable truncating types in error messages..
// @noFallthroughCasesInSwitchEnable error reporting for fallthrough cases in switch statements..
// @noImplicitAnyEnable error reporting for expressions and declarations with an implied `any` type...
// @noImplicitOverrideAdd `undefined` to a type when accessed using an index..
// @noImplicitReturnsEnable error reporting for codepaths that do not explicitly return in a function..
// @noImplicitThisEnable error reporting when `this` is given the type `any`..
// @noImplicitUseStrictDisable adding 'use strict' directives in emitted JavaScript files..
// @noLibDisable including any library files, including the default lib.d.ts..
// @noPropertyAccessFromIndexSignatureEnforces using indexed accessors for keys declared using an indexed type.
// @noResolveDisallow `import`s, `require`s or ``s from expanding the number of files TypeScript should add to a project..
// @noStrictGenericChecksDisable strict checking of generic signatures in function types..
// @noUncheckedIndexedAccessInclude 'undefined' in index signature results.
// @noUnusedLocalsEnable error reporting when a local variables aren't read..
// @noUnusedParametersRaise an error when a function parameter isn't read.
// @outDeprecated setting. Use `outFile` instead..
// @outDirSpecify an output folder for all emitted files..
// @outFileSpecify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output..
// @pathsSpecify a set of entries that re-map imports to additional lookup locations..
// @pluginsList of language service plugins..
// @preserveConstEnumsDisable erasing `const enum` declarations in generated code..
// @preserveSymlinksDisable resolving symlinks to their realpath. This correlates to the same flag in node..
// @preserveWatchOutputDisable wiping the console in watch mode.
// @prettyEnable color and formatting in output to make compiler errors easier to read.
// @reactNamespaceSpecify the object invoked for `createElement`. This only applies when targeting `react` JSX emit..
// @removeCommentsDisable emitting comments..
// @resolveJsonModuleEnable importing .json files.
// @rootDirSpecify the root folder within your source files..
// @rootDirsAllow multiple folders to be treated as one when resolving modules..
// @skipDefaultLibCheckSkip type checking .d.ts files that are included with TypeScript..
// @skipLibCheckSkip type checking all .d.ts files..
// @sourceMapCreate source map files for emitted JavaScript files..
// @sourceRootSpecify the root path for debuggers to find the reference source code..
// @strictEnable all strict type-checking options..
// @strictBindCallApplyCheck that the arguments for `bind`, `call`, and `apply` methods match the original function..
// @strictFunctionTypesWhen assigning functions, check to ensure parameters and the return values are subtype-compatible..
// @strictNullChecksWhen type checking, take into account `null` and `undefined`..
// @strictPropertyInitializationCheck for class properties that are declared but not set in the constructor..
// @stripInternalDisable emitting declarations that have `@internal` in their JSDoc comments..
// @suppressExcessPropertyErrorsDisable reporting of excess property errors during the creation of object literals..
// @suppressImplicitAnyIndexErrorsSuppress `noImplicitAny` errors when indexing objects that lack index signatures..
// @targetSet the JavaScript language version for emitted JavaScript and include compatible library declarations..
// @traceResolutionLog paths used during the `moduleResolution` process..
// @tsBuildInfoFileSpecify the folder for .tsbuildinfo incremental compilation files..
// @typeRootsSpecify multiple folders that act like `./node_modules/@types`..
// @typesSpecify type package names to be included without being referenced in a source file..
// @useDefineForClassFieldsEmit ECMAScript-standard-compliant class fields..
// @useUnknownInCatchVariablesType catch clause variables as 'unknown' instead of 'any'..