tsc CLI Options

Using the CLI

Running tsc locally will compile the closest project defined by a tsconfig.json, or you can compile a set of TypeScript files by passing in a glob of files you want. When input files are specified on the command line, tsconfig.json files are ignored.

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

Flag Type
--all

boolean

Show all compiler options.

--help

boolean

Gives local information for help on the CLI.

--init

boolean

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

--listFilesOnly

boolean

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

--locale

string

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

--project

string

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

--showConfig

boolean

Print the final configuration instead of building.

--version

boolean

Print the compiler's version.

Build Options

Flag Type
--build

boolean

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

--clean

boolean

Delete the outputs of all projects.

--dry

boolean

Show what would be built (or deleted, if specified with '--clean')

--force

boolean

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

--verbose

boolean

Enable verbose logging.

Watch Options

Flag Type
--excludeDirectories

list

Remove a list of directories from the watch process.

--excludeFiles

list

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

--fallbackPolling

fixedintervalpriorityintervaldynamicpriorityfixedchunksize

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

--synchronousWatchDirectory

boolean

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

--watch

boolean

Watch input files.

--watchDirectory

usefseventsfixedpollingintervaldynamicprioritypollingfixedchunksizepolling

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

--watchFile

fixedpollingintervalprioritypollingintervaldynamicprioritypollingfixedchunksizepollingusefseventsusefseventsonparentdirectory

Specify how the TypeScript watch mode works.

Compiler Flags

Flag Type Default
--allowArbitraryExtensions

boolean

false

Enable importing files with any extension, provided a declaration file is present.

--allowImportingTsExtensions

boolean

false

Allow imports to include TypeScript file extensions.

--allowJs

boolean

false

允许你的程序包含 JS 文件。使用 checkJS 来检查在这些文件中的错误。

--allowSyntheticDefaultImports

boolean

true if esModuleInterop is enabled, module is system, or moduleResolution is bundler; false otherwise.

当模块没有默认导入时,允许 'import x from y'

--allowUmdGlobalAccess

boolean

false

假设 UMD 的导入是全局可用的

--allowUnreachableCode

boolean

Disable error reporting for unreachable code.

--allowUnusedLabels

boolean

Disable error reporting for unused labels.

--alwaysStrict

boolean

true if strict; false otherwise.

Ensure 'use strict' is always emitted.

--assumeChangesOnlyAffectDirectDependencies

boolean

false

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

--baseUrl

string

为相对路径的模块名设置基准目录

--charset

string

utf8

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

--checkJs

boolean

false

在经过类型检查的 JavaScript 中报告错误。

--composite

boolean

false

启用约束以使工程可以引用其他工程来用于构建。

--customConditions

list

Conditions to set in addition to the resolver-specific defaults when resolving imports.

--declaration

boolean

true if composite; false otherwise.

为你工程中的 TypeScript 以及 JavaScript 文件生成 .d.ts 文件。

--declarationDir

string

Specify the output directory for generated declaration files.

--declarationMap

boolean

false

Create sourcemaps for d.ts files.

--diagnostics

boolean

false

Output compiler performance information after building.

--disableReferencedProjectLoad

boolean

false

Reduce the number of projects loaded automatically by TypeScript.

--disableSizeLimit

boolean

false

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

--disableSolutionSearching

boolean

false

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

--disableSourceOfProjectReferenceRedirect

boolean

false

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

--downlevelIteration

boolean

false

为迭代器对象生成更符合要求但更复杂的 JavaScript。

--emitBOM

boolean

false

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

--emitDeclarationOnly

boolean

false

Only output d.ts files and not JavaScript files.

--emitDecoratorMetadata

boolean

false

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

--esModuleInterop

boolean

true if module is node16 or nodenext; false otherwise.

为了便于支持导入 commonjs 模块生成额外的 JS

--exactOptionalPropertyTypes

boolean

false

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

--experimentalDecorators

boolean

false

Enable experimental support for TC39 stage 2 draft decorators.

--explainFiles

boolean

false

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

--extendedDiagnostics

boolean

false

Output more detailed compiler performance information after building.

--forceConsistentCasingInFileNames

boolean

true

Ensure that casing is correct in imports.

--generateCpuProfile

string

profile.cpuprofile

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

--generateTrace

string

Generates an event trace and a list of types.

--importHelpers

boolean

false

允许每个项目从 tslib 中导入一次辅助函数,而不是在每个文件中都包含他们。

--importsNotUsedAsValues

removepreserveerror

remove

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

--incremental

boolean

true if composite; false otherwise.

为支持增量编译工程,保存 .tsbuildinfo 文件

--inlineSourceMap

boolean

false

Include sourcemap files inside the emitted JavaScript.

--inlineSources

boolean

false

Include source code in the sourcemaps inside the emitted JavaScript.

--isolatedDeclarations

boolean

false

Require sufficient annotation on exports so other tools can trivially generate declaration files.

--isolatedModules

boolean

true if verbatimModuleSyntax; false otherwise.

确保每个文件都可以不依赖于其他导入而被安全转译。

--jsx

preservereactreact-nativereact-jsxreact-jsxdev

JSX 代码生成

--jsxFactory

string

React.createElement

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

--jsxFragmentFactory

string

React.Fragment

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

--jsxImportSource

string

react

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

--keyofStringsOnly

boolean

false

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

--lib

list

描述目标运行时环境的声明文件列表。

--listEmittedFiles

boolean

false

Print the names of emitted files after a compilation.

--listFiles

boolean

false

Print all of the files read during the compilation.

--mapRoot

string

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

--maxNodeModuleJsDepth

number

0

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

--module

nonecommonjsamdumdsystemes6/es2015es2020es2022esnextnode16nodenextpreserve

CommonJS if target is ES5; ES6/ES2015 otherwise.

模块代码生成。

--moduleDetection

legacyautoforce

"auto": Treat files with imports, exports, import.meta, jsx (with jsx: react-jsx), or esm format (with module: node16+) as modules.

Specify what method is used to detect whether a file is a script or a module.

--moduleResolution

classicnode10/nodenode16nodenextbundler

Classic if module is AMD, UMD, System, or ES6/ES2015; Matches if module is node16 or nodenext; Node otherwise.

允许 TypeScript 1.6 的模块解析策略

--moduleSuffixes

list

List of file name suffixes to search when resolving a module.

--newLine

crlflf

lf

Set the newline character for emitting files.

--noCheck

boolean

false

Disable full type checking (only critical parse and emit errors will be reported).

--noEmit

boolean

false

不在编译中生产文件。

--noEmitHelpers

boolean

false

Disable generating custom helper functions like __extends in compiled output.

--noEmitOnError

boolean

false

Disable emitting files if any type checking errors are reported.

--noErrorTruncation

boolean

false

Disable truncating types in error messages.

--noFallthroughCasesInSwitch

boolean

false

Enable error reporting for fallthrough cases in switch statements.

--noImplicitAny

boolean

true if strict; false otherwise.

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

--noImplicitOverride

boolean

false

Ensure overriding members in derived classes are marked with an override modifier.

--noImplicitReturns

boolean

false

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

--noImplicitThis

boolean

true if strict; false otherwise.

Enable error reporting when this is given the type any.

--noImplicitUseStrict

boolean

false

Disable adding 'use strict' directives in emitted JavaScript files.

--noLib

boolean

false

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

--noPropertyAccessFromIndexSignature

boolean

false

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

--noResolve

boolean

false

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

--noStrictGenericChecks

boolean

false

Disable strict checking of generic signatures in function types.

--noUncheckedIndexedAccess

boolean

false

Add undefined to a type when accessed using an index.

--noUncheckedSideEffectImports

boolean

false

Check side effect imports.

--noUnusedLocals

boolean

false

Enable error reporting when local variables aren't read.

--noUnusedParameters

boolean

false

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

--out

string

Deprecated setting. Use outFile instead.

--outDir

string

为所有生成的文件设置一个输出目录。

--outFile

string

将所有输出打包到一个 .js 文件中。如果 declaration 为 true 还可以指定一个 .d.ts 文件。

--paths

object

一组用于寻找模块导入的路径

--plugins

list

要包含的语言服务插件列表

--preserveConstEnums

boolean

true if isolatedModules; false otherwise.

Disable erasing const enum declarations in generated code.

--preserveSymlinks

boolean

false

不解析符号链接路径

--preserveValueImports

boolean

false

Preserve unused imported values in the JavaScript output that would otherwise be removed.

--preserveWatchOutput

boolean

false

Disable wiping the console in watch mode.

--pretty

boolean

true

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

--reactNamespace

string

React

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

--removeComments

boolean

false

不生成注释。

--resolveJsonModule

boolean

false

Enable importing .json files.

--resolvePackageJsonExports

boolean

true when moduleResolution is node16, nodenext, or bundler; otherwise false

Use the package.json 'exports' field when resolving package imports.

--resolvePackageJsonImports

boolean

true when moduleResolution is node16, nodenext, or bundler; otherwise false

Use the package.json 'imports' field when resolving imports.

--rootDir

string

Computed from the list of input files.

设置你源码的根目录。

--rootDirs

list

Computed from the list of input files.

设置多个根目录

--skipDefaultLibCheck

boolean

false

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

--skipLibCheck

boolean

false

Skip type checking all .d.ts files.

--sourceMap

boolean

false

为生成的 JavaScript 文件生成 source map 文件。

--sourceRoot

string

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

--stopBuildOnErrors

boolean

Skip building downstream projects on error in upstream project.

--strict

boolean

false

Enable all strict type-checking options.

--strictBindCallApply

boolean

true if strict; false otherwise.

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

--strictBuiltinIteratorReturn

boolean

false, unless strict is set

Built-in iterators are instantiated with a TReturn type of undefined instead of any.

--strictFunctionTypes

boolean

true if strict; false otherwise.

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

--strictNullChecks

boolean

true if strict; false otherwise.

When type checking, take into account null and undefined.

--strictPropertyInitialization

boolean

true if strict; false otherwise.

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

--stripInternal

boolean

false

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

--suppressExcessPropertyErrors

boolean

false

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

--suppressImplicitAnyIndexErrors

boolean

false

Suppress noImplicitAny errors when indexing objects that lack index signatures.

--target

es3es5es6/es2015es2016es2017es2018es2019es2020es2021es2022es2023esnext

ES5

设置生成的 JavaScript 语言的版本,并且会包含兼容的库(环境)的定义。

--traceResolution

boolean

false

Log paths used during the moduleResolution process.

--tsBuildInfoFile

string

.tsbuildinfo

为 .tsbuildinfo 增量编译信息指定目录。

--typeRoots

list

TypeScript 应该去哪些路径寻找类型定义

--types

list

用于创建一个允许包含在编译过程中的类型列表

--useDefineForClassFields

boolean

true if target is ES2022 or higher, including ESNext; false otherwise.

Emit ECMAScript-standard-compliant class fields.

--useUnknownInCatchVariables

boolean

true if strict; false otherwise.

Default catch clause variables as unknown instead of any.

--verbatimModuleSyntax

boolean

false

Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting.

The TypeScript docs are an open source project. Help us improve these pages by sending a Pull Request

Contributors to this page:
MHMohamed Hegazy  (96)
DRDaniel Rosenwasser  (19)
ADAxel D  (14)
OTOrta Therox  (7)
RCRyan Cavanaugh  (7)
44+

Last updated: 2024年11月22日