是否可以通过tsc转换typescript来禁用类型检查以加快转换?

时间:2017-08-29 22:53:01

标签: performance typescript configuration tsc

TypeScript会在转换时检查整个代码库,即使实际只有一个文件发生了更改。对于小型项目,这很好,但是自从我们的代码库增长以来,需要相当长的时间。

在开发过程中,我希望我的单元测试能够快速响应。单元测试应该尽快运行。

不幸的是,我必须等待每次运行大约10-15秒才能进行单元测试甚至开始,因为tsc需要花费很长时间才能完成,而那时花费了60%-80%在检查。

这些示例运行只是在一个文件中删除和添加换行符:

yarn tsc v0.27.5
$ "/home/philipp/fancyProject/node_modules/.bin/tsc" "--watch" "--diagnostics"
Files:           511
Lines:        260611
Nodes:        898141
Identifiers:  323004
Symbols:      863060
Types:        302553
Memory used: 704680K
I/O read:      0.17s
I/O write:     0.09s
Parse time:    2.61s
Bind time:     0.95s
Check time:    7.65s
Emit time:     1.45s
Total time:   12.65s
00:35:34 - Compilation complete. Watching for file changes.


00:41:58 - File change detected. Starting incremental compilation...


Files:            511
Lines:         260612
Nodes:         898141
Identifiers:   323004
Symbols:       863060
Types:         302553
Memory used: 1085950K
I/O read:       0.00s
I/O write:      0.04s
Parse time:     0.68s
Bind time:      0.00s
Check time:    12.65s
Emit time:      1.36s
Total time:    14.69s
00:42:13 - Compilation complete. Watching for file changes.


00:42:17 - File change detected. Starting incremental compilation...


Files:            511
Lines:         260611
Nodes:         898141
Identifiers:   323004
Symbols:       863060
Types:         302553
Memory used: 1106446K
I/O read:       0.00s
I/O write:      0.12s
Parse time:     0.32s
Bind time:      0.01s
Check time:     9.28s
Emit time:      0.89s
Total time:    10.50s
00:42:27 - Compilation complete. Watching for file changes.

我想知道是否有办法告诉打字稿:

只需将所有内容视为正常,然后尽快将JavaScript转储到磁盘上。

我想首先确保我的单元测试通过,以便有一个快速的反馈循环。

由于我的IDE负责处理我目前正在处理的文件中的类型检查,所以我在检查转换时很少有错误。如果有一个大问题,我的单元测试应该抓住它们。

在构建项目时,我会使用带有检查的经典tsc。正如我所说,这仅用于开发并具有快速反馈循环。

1 个答案:

答案 0 :(得分:0)

  1. 开始使用WebPack
  2. 添加awesome-typescript-loader
  3. transpileOnly设置为true
  4. 您还可以更改其他参数,这可以提高速度:ignoreDiagnosticsforceIsolatedModules等。

相关问题