Skip to content
赞助商
虚位以待
虚位以待
虚位以待
虚位以待
虚位以待
虚位以待
虚位以待
虚位以待
虚位以待
虚位以待
虚位以待
虚位以待
虚位以待
虚位以待
虚位以待
虚位以待
虚位以待

编译器诊断 ​

diagnostics 已弃用 ​

用于输出诊断信息以进行调试。此命令是 extendedDiagnostics 的子集,后者提供更面向用户的结果,且更易于解释。

如果 TypeScript 编译器工程师要求你在编译中使用此标志提供结果,使用 extendedDiagnostics 代替是没有坏处的。

explainFiles ​

  • 发布版本: 4.2

打印 TypeScript 视为项目一部分的文件名称以及它们成为编译一部分的原因。

例如,使用这个仅包含单个 index.ts 文件的项目:

sh
example
├── index.ts
├── package.json
└── tsconfig.json

使用将 explainFiles 设置为 true 的 tsconfig.json:

json
{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "explainFiles": true
  }
}

在此文件夹上运行 TypeScript 将输出如下内容:

❯ tsc
node_modules/typescript/lib/lib.d.ts
  Default library for target 'es5'
node_modules/typescript/lib/lib.es5.d.ts
  Library referenced via 'es5' from file 'node_modules/typescript/lib/lib.d.ts'
node_modules/typescript/lib/lib.dom.d.ts
  Library referenced via 'dom' from file 'node_modules/typescript/lib/lib.d.ts'
node_modules/typescript/lib/lib.webworker.importscripts.d.ts
  Library referenced via 'webworker.importscripts' from 
    file 'node_modules/typescript/lib/lib.d.ts'
node_modules/typescript/lib/lib.scripthost.d.ts
  Library referenced via 'scripthost' 
    from file 'node_modules/typescript/lib/lib.d.ts'
index.ts
  Matched by include pattern '**/*' in 'tsconfig.json'

上面的输出显示了:

  • 基于 target 的初始 lib.d.ts 查找,以及引用的 .d.ts 文件链
  • 通过 include 的默认模式定位的 index.ts 文件

此选项旨在调试文件如何成为编译的一部分。

extendedDiagnostics ​

你可以使用此标志来发现 TypeScript 在编译时的时间花费在哪里。 这是用于了解代码库整体性能特征的工具。

你可以在 wiki 的性能部分中了解更多关于如何测量和理解输出的信息。

generateCpuProfile ​

  • 默认值: profile.cpuprofile

  • 发布版本: 3.7

此选项使你有机会在编译器运行期间让 TypeScript 输出 v8 CPU 配置文件。CPU 配置文件可以深入了解构建缓慢的原因。

此选项只能通过 CLI 使用:--generateCpuProfile tsc-output.cpuprofile。

sh
npm run tsc --generateCpuProfile tsc-output.cpuprofile

此文件可以在基于 Chromium 的浏览器(如 Chrome 或 Edge Developer)的 CPU 分析器部分中打开。你可以在 TypeScript wiki 的性能部分中了解更多关于理解编译器性能的信息。

generateTrace ​

  • 发布版本: 4.1

生成事件跟踪和类型列表。

listEmittedFiles ​

  • 发布版本: 2.0

将编译中生成的文件名称打印到终端。

此标志在两种情况下很有用:

  • 你想将 TypeScript 转译作为构建链的一部分,其中文件名在下一个命令中处理。
  • 你不确定 TypeScript 是否包含了你期望的文件,作为调试文件包含设置的一部分。

例如:

example
├── index.ts
├── package.json
└── tsconfig.json

使用:

json
{
  "compilerOptions": {
    "declaration": true,
    "listEmittedFiles": true
  }
}

将输出如下路径:

$ npm run tsc

path/to/example/index.js
path/to/example/index.d.ts

通常,TypeScript 在成功时静默返回。

listFiles ​

打印编译中文件名称。当你不确定 TypeScript 是否包含了你期望的文件时,这很有用。

例如:

example
├── index.ts
├── package.json
└── tsconfig.json

使用:

json
{
  "compilerOptions": {
    "listFiles": true
  }
}

将输出如下路径:

$ npm run tsc
path/to/example/node_modules/typescript/lib/lib.d.ts
path/to/example/node_modules/typescript/lib/lib.es5.d.ts
path/to/example/node_modules/typescript/lib/lib.dom.d.ts
path/to/example/node_modules/typescript/lib/lib.webworker.importscripts.d.ts
path/to/example/node_modules/typescript/lib/lib.scripthost.d.ts
path/to/example/index.ts

注意,如果使用 TypeScript 4.2,建议使用 explainFiles,它还会提供添加文件的原因说明。

noCheck ​

  • 发布版本: 5.6

禁用完整的类型检查(仅报告关键的解析和输出错误)。

traceResolution ​

  • 发布版本: 2.0

当你试图调试为什么某个模块没有被包含时,可以将 traceResolution 设置为 true,让 TypeScript 打印每个已处理文件的解析过程信息。