编译选项
编译选项
选项
类型
默认值
描述
--allowJs
boolean
false
允许编译javascript文件。
--allowSyntheticDefaultImports
boolean
module === "system"
或设置了--esModuleInterop
允许从没有设置默认导出的模块中默认导入。这并不影响代码的输出,仅为了类型检查。
--allowUnreachableCode
boolean
false
不报告执行不到的代码错误。
--allowUnusedLabels
boolean
false
不报告未使用的标签错误。
--alwaysStrict
boolean
false
以严格模式解析并为每个源文件生成"use strict"
语句
--baseUrl
string
--build
-b
boolean
false
--charset
string
"utf8"
输入文件的字符集。
--checkJs
boolean
false
在.js文件中报告错误。与--allowJs
配合使用。
--composite
boolean
true
确保TypeScript能够找到编译当前工程所需要的引用工程的输出位置。
--declaration
-d
boolean
false
生成相应的.d.ts
文件。
--declarationDir
string
生成声明文件的输出路径。
--diagnostics
boolean
false
显示诊断信息。
--disableSizeLimit
boolean
false
禁用JavaScript工程体积大小的限制
--emitBOM
boolean
false
在输出文件的开头加入BOM头(UTF-8 Byte Order Mark)。
--emitDecoratorMetadata
[1]
boolean
false
--experimentalDecorators
[1]
boolean
false
启用实验性的ES装饰器。
--extendedDiagnostics
boolean
false
显示详细的诊段信息。
--forceConsistentCasingInFileNames
boolean
false
禁止对同一个文件的不一致的引用。
--generateCpuProfile
string
profile.cpuprofile
在指定目录生成CPU资源使用报告。若传入的是已创建的目录名,将在此目录下生成以时间戳命名的报告。
--help
-h
打印帮助信息。
--importHelpers
string
--importsNotUsedAsValues
string
remove
用于设置针对于类型导入的代码生成和代码检查的行为。"remove"
和"preserve"
设置了是否对未使用的导入了模块副作用的导入语句生成相关代码,"error"
则强制要求只用作类型的模块导入必须使用import type
语句。
--inlineSourceMap
boolean
false
生成单个sourcemaps文件,而不是将每sourcemaps生成不同的文件。
--inlineSources
boolean
false
将代码与sourcemaps生成到一个文件中,要求同时设置了--inlineSourceMap
或--sourceMap
属性。
--init
初始化TypeScript项目并创建一个tsconfig.json
文件。
--isolatedModules
boolean
false
--jsx
string
"preserve"
--jsxFactory
string
"React.createElement"
指定生成目标为react JSX时,使用的JSX工厂函数,比如React.createElement
或h
。
--lib
string[]
编译过程中需要引入的库文件的列表。 可能的值为: ► ES5
► ES6
► ES2015
► ES7
► ES2016
► ES2017
► ES2018
► ESNext
► DOM
► DOM.Iterable
► WebWorker
► ScriptHost
► ES2015.Core
► ES2015.Collection
► ES2015.Generator
► ES2015.Iterable
► ES2015.Promise
► ES2015.Proxy
► ES2015.Reflect
► ES2015.Symbol
► ES2015.Symbol.WellKnown
► ES2016.Array.Include
► ES2017.object
► ES2017.Intl
► ES2017.SharedMemory
► ES2017.String
► ES2017.TypedArrays
► ES2018.Intl
► ES2018.Promise
► ES2018.RegExp
► ESNext.AsyncIterable
► ESNext.Array
► ESNext.Intl
► ESNext.Symbol
注意:如果--lib
没有指定默认注入的库的列表。默认注入的库为: ► 针对于--target ES5
:DOM,ES5,ScriptHost
► 针对于--target ES6
:DOM,ES6,DOM.Iterable,ScriptHost
--listEmittedFiles
boolean
false
打印出编译后生成文件的名字。
--listFiles
boolean
false
编译过程中打印文件名。
--locale
string
(platform specific)
显示错误信息时使用的语言,比如:en-us。
--mapRoot
string
为调试器指定指定sourcemap文件的路径,而不是使用生成时的路径。当.map
文件是在运行时指定的,并不同于js
文件的地址时使用这个标记。指定的路径会嵌入到sourceMap
里告诉调试器到哪里去找它们。使用此标识并不会新创建指定目录并生成map文件在指定路径下。而是增加一个构建后的步骤,把相应文件移动到指定路径下。
--maxNodeModuleJsDepth
number
0
node_modules依赖的最大搜索深度并加载JavaScript文件。仅适用于--allowJs
。
--module
-m
string
target === "ES6" ? "ES6" : "commonjs"
指定生成哪个模块系统代码:"None"
,"CommonJS"
,"AMD"
,"System"
,"UMD"
,"ES6"
或"ES2015"
。 ► 只有"AMD"
和"System"
能和--outFile
一起使用。 ►"ES6"
和"ES2015"
可使用在目标输出为"ES5"
或更低的情况下。
--moduleResolution
string
module === "AMD" or "System" or "ES6" ? "Classic" : "Node"
--newLine
string
(platform specific)
当生成文件时指定行结束符:"crlf"
(windows)或"lf"
(unix)。
--noEmit
boolean
false
不生成输出文件。
--noEmitHelpers
boolean
false
不在输出文件中生成用户自定义的帮助函数代码,如__extends
。
--noEmitOnError
boolean
false
报错时不生成输出文件。
--noErrorTruncation
boolean
false
不截短错误消息。
--noFallthroughCasesInSwitch
boolean
false
报告switch语句的fallthrough错误。(即,不允许switch的case语句贯穿)
--noImplicitAny
boolean
false
在表达式和声明上有隐含的any
类型时报错。
--noImplicitReturns
boolean
false
不是函数的所有返回路径都有返回值时报错。
--noImplicitThis
boolean
false
当this
表达式的值为any
类型的时候,生成一个错误。
--noImplicitUseStrict
boolean
false
模块输出中不包含"use strict"
指令。
--noLib
boolean
false
不包含默认的库文件(lib.d.ts
)。
--noResolve
boolean
false
不把/// <reference``>
或模块导入的文件加到编译文件列表。
--noStrictGenericChecks
boolean
false
禁用在函数类型里对泛型签名进行严格检查。
--noUnusedLocals
boolean
false
若有未使用的局部变量则抛错。
--noUnusedParameters
boolean
false
若有未使用的参数则抛错。
--out
string
弃用。使用 --outFile
代替。
--outDir
string
重定向输出目录。
--outFile
string
paths
[2]
Object
--preserveConstEnums
boolean
false
--preserveSymlinks
boolean
false
不把符号链接解析为其真实路径;将符号链接文件视为真正的文件。
--preserveWatchOutput
boolean
false
保留watch模式下过时的控制台输出。
--pretty
[1]
boolean
false
给错误和消息设置样式,使用颜色和上下文。
--project
-p
string
--reactNamespace
string
"React"
当目标为生成"react"
JSX时,指定createElement
和__spread
的调用对象
--removeComments
boolean
false
删除所有注释,除了以/!*
开头的版权信息。
--rootDir
string
(common root directory is computed from the list of input files)
仅用来控制输出的目录结构--outDir
。
rootDirs
[2]
string[]
--showConfig
boolean
false
不真正执行build,而是显示build使用的配置文件信息。
--skipDefaultLibCheck
boolean
false
--skipLibCheck
boolean
false
忽略所有的声明文件(*.d.ts
)的类型检查。
--sourceMap
boolean
false
生成相应的.map
文件。
--sourceRoot
string
指定TypeScript源文件的路径,以便调试器定位。当TypeScript文件的位置是在运行时指定时使用此标记。路径信息会被加到sourceMap
里。
--strict
boolean
false
启用所有严格检查选项。 包含--noImplicitAny
, --noImplicitThis
, --alwaysStrict
, --strictBindCallApply
, --strictNullChecks
, --strictFunctionTypes
和--strictPropertyInitialization
.
--strictFunctionTypes
boolean
false
禁用函数参数双向协变检查。
--strictPropertyInitialization
boolean
false
确保类的非undefined
属性已经在构造函数里初始化。若要令此选项生效,需要同时启用--strictNullChecks
。
--strictNullChecks
boolean
false
在严格的null
检查模式下,null
和undefined
值不包含在任何类型里,只允许用它们自己和any
来赋值(有个例外,undefined
可以赋值到void
)。
--suppressExcessPropertyErrors
[1]
boolean
false
阻止对对象字面量的额外属性检查。
--suppressImplicitAnyIndexErrors
boolean
false
--target
-t
string
"ES3"
--traceResolution
boolean
false
生成模块解析日志信息
--types
string[]
--typeRoots
string[]
--version
-v
打印编译器版本号。
--watch
-w
[1] 这些选项是试验性的。
[2] 这些选项只能在
tsconfig.json
里使用,不能在命令行使用。
相关信息
在
tsconfig.json
文件里设置编译器选项。在MSBuild工程里设置编译器选项。
Last updated
Was this helpful?