tsc CLI Options

Using the CLI

Running tsc locally will compile the closest project defined by a tsconfig.json, you can compile a set of TypeScript files by passing in a glob of files you want.

  1. sh
    # Run a compile based on a backwards look through the fs for a tsconfig.json
    tsc
    # Emit JS for just the index.ts with the compiler defaults
    tsc index.ts
    # Emit JS for any .ts files in the folder src, with the default settings
    tsc src/*.ts
    # Emit files referenced in with the compiler settings from tsconfig.production.json
    tsc --project tsconfig.production.json
    # Emit d.ts files for a js file with showing compiler options which are booleans
    tsc index.js --declaration --emitDeclarationOnly
    # Emit a single .js file from two files via compiler options which take string arguments
    tsc app.ts util.ts --target esnext --outfile index.js

Compiler Options

If you’re looking for more information about the compiler options in a tsconfig, check out the TSConfig Reference

CLI Commands

  1. </tr>
FlagType
—allboolean

Show all compiler options.

—generateTracestring

Generates an event trace and a list of types.

—helpboolean

Gives local information for help on the CLI.

—initboolean

Initializes a TypeScript project and creates a tsconfig.json file.

—listFilesOnlyboolean

Print names of files that are part of the compilation and then stop processing.

—localestring

Set the language of the messaging from TypeScript. This does not affect emit.

—projectstring

Compile the project given the path to its configuration file, or to a folder with a ‘tsconfig.json’.

—showConfigboolean

Print the final configuration instead of building.

—versionboolean

Print the compiler’s version.

Build Options

  1. </tr>
FlagType
—buildboolean

Build one or more projects and their dependencies, if out of date

—cleanboolean

Delete the outputs of all projects.

—dryboolean

Show what would be built (or deleted, if specified with ‘—clean’)

—forceboolean

Build all projects, including those that appear to be up to date

—verboseboolean

Enable verbose logging

Watch Options

  1. </tr>
FlagType
—excludeDirectorieslist

Remove a list of directories from the watch process.

—excludeFileslist

Remove a list of files from the watch mode’s processing.

—fallbackPollingfixedPollingInterval, priorityPollingInterval, or dynamicPriorityPolling

Specify what approach the watcher should use if the system runs out of native file watchers.

—synchronousWatchDirectoryboolean

Synchronously call callbacks and update the state of directory watchers on platforms that don`t support recursive watching natively.

—watchboolean

Watch input files.

—watchDirectoryfixedPollingInterval, dynamicPriorityPolling, or useFsEvents

Specify how directories are watched on systems that lack recursive file-watching functionality.

—watchFilefixedPollingInterval, priorityPollingInterval, dynamicPriorityPolling, useFsEvents, or useFsEventsOnParentDirectory

Specify how the TypeScript watch mode works.

Compiler Flags

  1. </tr>
FlagTypeDefault
—allowJsboolean

false

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

—allowSyntheticDefaultImportsboolean

module === “system” or esModuleInterop

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

—allowUmdGlobalAccessboolean

false

Allow accessing UMD globals from modules.

—allowUnreachableCodeboolean

undefined

Disable error reporting for unreachable code.

—allowUnusedLabelsboolean

undefined

Disable error reporting for unused labels.

—alwaysStrictboolean

false, unless strict is set

Ensure ‘use strict’ is always emitted.

—assumeChangesOnlyAffectDirectDependenciesboolean

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

—baseUrlstring

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

—charsetstring

utf8

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

—checkJsboolean

false

Enable error reporting in type-checked JavaScript files.

—compositeboolean

false

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

—declarationboolean

false, unless composite is set

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

—declarationDirstring

n/a

Specify the output directory for generated declaration files.

—declarationMapboolean

false

Create sourcemaps for d.ts files.

—diagnosticsboolean

false

Output compiler performance information after building.

—disableReferencedProjectLoadboolean

Reduce the number of projects loaded automatically by TypeScript.

—disableSizeLimitboolean

false

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

—disableSolutionSearchingboolean

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

—disableSourceOfProjectReferenceRedirectboolean

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

—downlevelIterationboolean

false

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

—emitBOMboolean

false

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

—emitDeclarationOnlyboolean

false

Only output d.ts files and not JavaScript files.

—emitDecoratorMetadataboolean

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

—esModuleInteropboolean

false

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

—exactOptionalPropertyTypesboolean

Differentiate between undefined and not present when type checking

—experimentalDecoratorsboolean

Enable experimental support for TC39 stage 2 draft decorators.

—explainFilesboolean

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

—extendedDiagnosticsboolean

false

Output more detailed compiler performance information after building.

—forceConsistentCasingInFileNamesboolean

false

Ensure that casing is correct in imports.

—generateCpuProfilestring

profile.cpuprofile

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

—importHelpersboolean

false

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

—importsNotUsedAsValuesremove, preserve, or error

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

—incrementalboolean

true if composite, false otherwise

Save .tsbuildinfo files to allow for incremental compilation of projects.

—inlineSourceMapboolean

false

Include sourcemap files inside the emitted JavaScript.

—inlineSourcesboolean

false

Include source code in the sourcemaps inside the emitted JavaScript.

—isolatedModulesboolean

false

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

—jsxreact, react-jsx, react-jsxdev, react-native, or preserve

undefined

Specify what JSX code is generated.

—jsxFactorystring

React.createElement

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

—jsxFragmentFactorystring

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

—jsxImportSourcestring

react

Specify module specifier used to import the JSX factory functions when using jsx: react-jsx*.</p></td></tr><tr name="keyofStringsOnly"><td><code><a href="$889bbc2ea6ad166e.md#keyofStringsOnly">--keyofStringsOnly</a></code></td><td><code>boolean</code></td><td><p>false</p></td></tr><tr><td colspan="3"><p>Make keyof only return strings instead of string, numbers or symbols. Legacy option.</p></td></tr><tr name="lib"><td><code><a href="$889bbc2ea6ad166e.md#lib">--lib</a></code></td><td><code>list</code></td><td></td></tr><tr><td colspan="3"><p>Specify a set of bundled library declaration files that describe the target runtime environment.</p></td></tr><tr name="listEmittedFiles"><td><code><a href="$889bbc2ea6ad166e.md#listEmittedFiles">--listEmittedFiles</a></code></td><td><code>boolean</code></td><td><p>false</p></td></tr><tr><td colspan="3"><p>Print the names of emitted files after a compilation.</p></td></tr><tr name="listFiles"><td><code><a href="$889bbc2ea6ad166e.md#listFiles">--listFiles</a></code></td><td><code>boolean</code></td><td><p>false</p></td></tr><tr><td colspan="3"><p>Print all of the files read during the compilation.</p></td></tr><tr name="mapRoot"><td><code><a href="$889bbc2ea6ad166e.md#mapRoot">--mapRoot</a></code></td><td><code>string</code></td><td></td></tr><tr><td colspan="3"><p>Specify the location where debugger should locate map files instead of generated locations.</p></td></tr><tr name="maxNodeModuleJsDepth"><td><code><a href="$889bbc2ea6ad166e.md#maxNodeModuleJsDepth">--maxNodeModuleJsDepth</a></code></td><td><code>number</code></td><td><p>0</p></td></tr><tr><td colspan="3"><p>Specify the maximum folder depth used for checking JavaScript files from <code>node_modules</code>. Only applicable with <code>allowJs</code>.</p></td></tr><tr name="module"><td><code><a href="$889bbc2ea6ad166e.md#module">--module</a></code></td><td><code><code>CommonJS(default iftargetisES3orES5)</code>, <code></code>, <code>ES6</code>, <code>ES2015</code>, <code>ES2020</code>, <code></code>, <code>None</code>, <code>UMD</code>, <code>AMD</code>, <code>System</code>, or <code>ESNext</code></code></td><td></td></tr><tr><td colspan="3"><p>Specify what module code is generated.</p></td></tr><tr name="moduleResolution"><td><code><a href="$889bbc2ea6ad166e.md#moduleResolution">--moduleResolution</a></code></td><td><code></code></td><td><p>module === <code>AMD</code> or <code>UMD</code> or <code>System</code> or <code>ES6</code>, then <code>Classic</code><br><br>Otherwise <code>Node</code></p></td></tr><tr><td colspan="3"><p>Specify how TypeScript looks up a file from a given module specifier.</p></td></tr><tr name="newLine"><td><code><a href="$889bbc2ea6ad166e.md#newLine">--newLine</a></code></td><td><code></code></td><td><p>Platform specific</p></td></tr><tr><td colspan="3"><p>Set the newline character for emitting files.</p></td></tr><tr name="noEmit"><td><code><a href="$889bbc2ea6ad166e.md#noEmit">--noEmit</a></code></td><td><code>boolean</code></td><td><p>false</p></td></tr><tr><td colspan="3"><p>Disable emitting file from a compilation.</p></td></tr><tr name="noEmitHelpers"><td><code><a href="$889bbc2ea6ad166e.md#noEmitHelpers">--noEmitHelpers</a></code></td><td><code>boolean</code></td><td><p>false</p></td></tr><tr><td colspan="3"><p>Disable generating custom helper functions like <code>__extends</code> in compiled output.</p></td></tr><tr name="noEmitOnError"><td><code><a href="$889bbc2ea6ad166e.md#noEmitOnError">--noEmitOnError</a></code></td><td><code>boolean</code></td><td><p>false</p></td></tr><tr><td colspan="3"><p>Disable emitting files if any type checking errors are reported.</p></td></tr><tr name="noErrorTruncation"><td><code><a href="$889bbc2ea6ad166e.md#noErrorTruncation">--noErrorTruncation</a></code></td><td><code>boolean</code></td><td><p>false</p></td></tr><tr><td colspan="3"><p>Disable truncating types in error messages.</p></td></tr><tr name="noFallthroughCasesInSwitch"><td><code><a href="$889bbc2ea6ad166e.md#noFallthroughCasesInSwitch">--noFallthroughCasesInSwitch</a></code></td><td><code>boolean</code></td><td><p>false</p></td></tr><tr><td colspan="3"><p>Enable error reporting for fallthrough cases in switch statements.</p></td></tr><tr name="noImplicitAny"><td><code><a href="$889bbc2ea6ad166e.md#noImplicitAny">--noImplicitAny</a></code></td><td><code>boolean</code></td><td><p><code>false</code>, unless <code>strict</code> is set</p></td></tr><tr><td colspan="3"><p>Enable error reporting for expressions and declarations with an implied <code>any</code> type..</p></td></tr><tr name="noImplicitOverride"><td><code><a href="$889bbc2ea6ad166e.md#noImplicitOverride">--noImplicitOverride</a></code></td><td><code>boolean</code></td><td></td></tr><tr><td colspan="3"><p>Ensure overriding members in derived classes are marked with an override modifier.</p></td></tr><tr name="noImplicitReturns"><td><code><a href="$889bbc2ea6ad166e.md#noImplicitReturns">--noImplicitReturns</a></code></td><td><code>boolean</code></td><td><p>false</p></td></tr><tr><td colspan="3"><p>Enable error reporting for codepaths that do not explicitly return in a function.</p></td></tr><tr name="noImplicitThis"><td><code><a href="$889bbc2ea6ad166e.md#noImplicitThis">--noImplicitThis</a></code></td><td><code>boolean</code></td><td><p><code>false</code>, unless <code>strict</code> is set</p></td></tr><tr><td colspan="3"><p>Enable error reporting when <code>this</code> is given the type <code>any</code>.</p></td></tr><tr name="noImplicitUseStrict"><td><code><a href="$889bbc2ea6ad166e.md#noImplicitUseStrict">--noImplicitUseStrict</a></code></td><td><code>boolean</code></td><td><p>false</p></td></tr><tr><td colspan="3"><p>Disable adding 'use strict' directives in emitted JavaScript files.</p></td></tr><tr name="noLib"><td><code><a href="$889bbc2ea6ad166e.md#noLib">--noLib</a></code></td><td><code>boolean</code></td><td><p>false</p></td></tr><tr><td colspan="3"><p>Disable including any library files, including the default lib.d.ts.</p></td></tr><tr name="noPropertyAccessFromIndexSignature"><td><code><a href="$889bbc2ea6ad166e.md#noPropertyAccessFromIndexSignature">--noPropertyAccessFromIndexSignature</a></code></td><td><code>boolean</code></td><td><p>false</p></td></tr><tr><td colspan="3"><p>Enforces using indexed accessors for keys declared using an indexed type</p></td></tr><tr name="noResolve"><td><code><a href="$889bbc2ea6ad166e.md#noResolve">--noResolve</a></code></td><td><code>boolean</code></td><td><p>false</p></td></tr><tr><td colspan="3"><p>Disallow <code>import</code>s, <code>require</code>s or <code>&lt;reference&gt;</code>s from expanding the number of files TypeScript should add to a project.</p></td></tr><tr name="noStrictGenericChecks"><td><code><a href="$889bbc2ea6ad166e.md#noStrictGenericChecks">--noStrictGenericChecks</a></code></td><td><code>boolean</code></td><td><p>false</p></td></tr><tr><td colspan="3"><p>Disable strict checking of generic signatures in function types.</p></td></tr><tr name="noUncheckedIndexedAccess"><td><code><a href="$889bbc2ea6ad166e.md#noUncheckedIndexedAccess">--noUncheckedIndexedAccess</a></code></td><td><code>boolean</code></td><td></td></tr><tr><td colspan="3"><p>Add <code>undefined</code> to a type when accessed using an index.</p></td></tr><tr name="noUnusedLocals"><td><code><a href="$889bbc2ea6ad166e.md#noUnusedLocals">--noUnusedLocals</a></code></td><td><code>boolean</code></td><td><p>false</p></td></tr><tr><td colspan="3"><p>Enable error reporting when a local variables aren't read.</p></td></tr><tr name="noUnusedParameters"><td><code><a href="$889bbc2ea6ad166e.md#noUnusedParameters">--noUnusedParameters</a></code></td><td><code>boolean</code></td><td><p>false</p></td></tr><tr><td colspan="3"><p>Raise an error when a function parameter isn't read</p></td></tr><tr name="out"><td><code><a href="$889bbc2ea6ad166e.md#out">--out</a></code></td><td><code>string</code></td><td><p>n/a</p></td></tr><tr><td colspan="3"><p>Deprecated setting. Use <code>outFile</code> instead.</p></td></tr><tr name="outDir"><td><code><a href="$889bbc2ea6ad166e.md#outDir">--outDir</a></code></td><td><code>string</code></td><td><p>n/a</p></td></tr><tr><td colspan="3"><p>Specify an output folder for all emitted files.</p></td></tr><tr name="outFile"><td><code><a href="$889bbc2ea6ad166e.md#outFile">--outFile</a></code></td><td><code>string</code></td><td><p>n/a</p></td></tr><tr><td colspan="3"><p>Specify a file that bundles all outputs into one JavaScript file. If <code>declaration</code> is true, also designates a file that bundles all .d.ts output.</p></td></tr><tr name="paths"><td><code><a href="$889bbc2ea6ad166e.md#paths">--paths</a></code></td><td><code>object</code></td><td></td></tr><tr><td colspan="3"><p>Specify a set of entries that re-map imports to additional lookup locations.</p></td></tr><tr name="plugins"><td><code><a href="$889bbc2ea6ad166e.md#plugins">--plugins</a></code></td><td><code>list</code></td><td></td></tr><tr><td colspan="3"><p>Specify a list of language service plugins to include.</p></td></tr><tr name="preserveConstEnums"><td><code><a href="$889bbc2ea6ad166e.md#preserveConstEnums">--preserveConstEnums</a></code></td><td><code>boolean</code></td><td><p>false</p></td></tr><tr><td colspan="3"><p>Disable erasing <code>const enum</code> declarations in generated code.</p></td></tr><tr name="preserveSymlinks"><td><code><a href="$889bbc2ea6ad166e.md#preserveSymlinks">--preserveSymlinks</a></code></td><td><code>boolean</code></td><td><p>false</p></td></tr><tr><td colspan="3"><p>Disable resolving symlinks to their realpath. This correlates to the same flag in node.</p></td></tr><tr name="preserveWatchOutput"><td><code><a href="$889bbc2ea6ad166e.md#preserveWatchOutput">--preserveWatchOutput</a></code></td><td><code>boolean</code></td><td><p>false</p></td></tr><tr><td colspan="3"><p>Disable wiping the console in watch mode</p></td></tr><tr name="pretty"><td><code><a href="$889bbc2ea6ad166e.md#pretty">--pretty</a></code></td><td><code>boolean</code></td><td><p>true</p></td></tr><tr><td colspan="3"><p>Enable color and formatting in output to make compiler errors easier to read</p></td></tr><tr name="reactNamespace"><td><code><a href="$889bbc2ea6ad166e.md#reactNamespace">--reactNamespace</a></code></td><td><code>string</code></td><td><p>"React"</p></td></tr><tr><td colspan="3"><p>Specify the object invoked for <code>createElement</code>. This only applies when targeting <code>react</code> JSX emit.</p></td></tr><tr name="removeComments"><td><code><a href="$889bbc2ea6ad166e.md#removeComments">--removeComments</a></code></td><td><code>boolean</code></td><td><p>false</p></td></tr><tr><td colspan="3"><p>Disable emitting comments.</p></td></tr><tr name="resolveJsonModule"><td><code><a href="$889bbc2ea6ad166e.md#resolveJsonModule">--resolveJsonModule</a></code></td><td><code>boolean</code></td><td><p>false</p></td></tr><tr><td colspan="3"><p>Enable importing .json files</p></td></tr><tr name="rootDir"><td><code><a href="$889bbc2ea6ad166e.md#rootDir">--rootDir</a></code></td><td><code>string</code></td><td><p>Computed from the list of input files</p></td></tr><tr><td colspan="3"><p>Specify the root folder within your source files.</p></td></tr><tr name="rootDirs"><td><code><a href="$889bbc2ea6ad166e.md#rootDirs">--rootDirs</a></code></td><td><code>list</code></td><td></td></tr><tr><td colspan="3"><p>Allow multiple folders to be treated as one when resolving modules.</p></td></tr><tr name="skipDefaultLibCheck"><td><code><a href="$889bbc2ea6ad166e.md#skipDefaultLibCheck">--skipDefaultLibCheck</a></code></td><td><code>boolean</code></td><td><p>false</p></td></tr><tr><td colspan="3"><p>Skip type checking .d.ts files that are included with TypeScript.</p></td></tr><tr name="skipLibCheck"><td><code><a href="$889bbc2ea6ad166e.md#skipLibCheck">--skipLibCheck</a></code></td><td><code>boolean</code></td><td><p>false</p></td></tr><tr><td colspan="3"><p>Skip type checking all .d.ts files.</p></td></tr><tr name="sourceMap"><td><code><a href="$889bbc2ea6ad166e.md#sourceMap">--sourceMap</a></code></td><td><code>boolean</code></td><td><p>false</p></td></tr><tr><td colspan="3"><p>Create source map files for emitted JavaScript files.</p></td></tr><tr name="sourceRoot"><td><code><a href="$889bbc2ea6ad166e.md#sourceRoot">--sourceRoot</a></code></td><td><code>string</code></td><td></td></tr><tr><td colspan="3"><p>Specify the root path for debuggers to find the reference source code.</p></td></tr><tr name="strict"><td><code><a href="$889bbc2ea6ad166e.md#strict">--strict</a></code></td><td><code>boolean</code></td><td><p>false</p></td></tr><tr><td colspan="3"><p>Enable all strict type checking options.</p></td></tr><tr name="strictBindCallApply"><td><code><a href="$889bbc2ea6ad166e.md#strictBindCallApply">--strictBindCallApply</a></code></td><td><code>boolean</code></td><td><p><code>false</code>, unless <code>strict</code> is set</p></td></tr><tr><td colspan="3"><p>Check that the arguments for <code>bind</code>, <code>call</code>, and <code>apply</code> methods match the original function.</p></td></tr><tr name="strictFunctionTypes"><td><code><a href="$889bbc2ea6ad166e.md#strictFunctionTypes">--strictFunctionTypes</a></code></td><td><code>boolean</code></td><td><p><code>false</code>, unless <code>strict</code> is set</p></td></tr><tr><td colspan="3"><p>When assigning functions, check to ensure parameters and the return values are subtype-compatible.</p></td></tr><tr name="strictNullChecks"><td><code><a href="$889bbc2ea6ad166e.md#strictNullChecks">--strictNullChecks</a></code></td><td><code>boolean</code></td><td><p><code>false</code>, unless <code>strict</code> is set</p></td></tr><tr><td colspan="3"><p>When type checking, take into account <code>null</code> and <code>undefined</code>.</p></td></tr><tr name="strictPropertyInitialization"><td><code><a href="$889bbc2ea6ad166e.md#strictPropertyInitialization">--strictPropertyInitialization</a></code></td><td><code>boolean</code></td><td><p><code>false</code>, unless <code>strict</code> is set</p></td></tr><tr><td colspan="3"><p>Check for class properties that are declared but not set in the constructor.</p></td></tr><tr name="stripInternal"><td><code><a href="$889bbc2ea6ad166e.md#stripInternal">--stripInternal</a></code></td><td><code>boolean</code></td><td></td></tr><tr><td colspan="3"><p>Disable emitting declarations that have <code>@internal</code> in their JSDoc comments.</p></td></tr><tr name="suppressExcessPropertyErrors"><td><code><a href="$889bbc2ea6ad166e.md#suppressExcessPropertyErrors">--suppressExcessPropertyErrors</a></code></td><td><code>boolean</code></td><td><p>false</p></td></tr><tr><td colspan="3"><p>Disable reporting of excess property errors during the creation of object literals.</p></td></tr><tr name="suppressImplicitAnyIndexErrors"><td><code><a href="$889bbc2ea6ad166e.md#suppressImplicitAnyIndexErrors">--suppressImplicitAnyIndexErrors</a></code></td><td><code>boolean</code></td><td><p>false</p></td></tr><tr><td colspan="3"><p>Suppress <code>noImplicitAny</code> errors when indexing objects that lack index signatures.</p></td></tr><tr name="target"><td><code><a href="$889bbc2ea6ad166e.md#target">--target</a></code></td><td><code><code>ES3(default)</code>, <code>ES5</code>, <code>ES6/ES2015(synonymous)</code>, <code>ES7/ES2016</code>, <code>ES2017</code>, <code>ES2018</code>, <code>ES2019</code>, <code>ES2020</code>, or <code>ESNext`

ES3

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

—traceResolutionboolean

false

Log paths used during the moduleResolution process.

—tsBuildInfoFilestring

.tsbuildinfo

Specify the folder for .tsbuildinfo incremental compilation files.

—typeRootslist

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

—typeslist

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

—useDefineForClassFieldsboolean

true for ES2022 and above, including ESNext.

Emit ECMAScript-standard-compliant class fields.

—useUnknownInCatchVariablesboolean

false, unless strict is set

Default catch clause variables as unknown instead of any.