vscode 打字计数
Sharing a simple tip that saved me hours of my life over the last 3 years working with TypeScript codebases (especially large ones!).
分享一个简单的技巧 ,在使用TypeScript代码库(尤其是大型代码库)的过程中, 为我节省了过去三年的生命 。
I wish I knew it earlier when I was just getting started with TypeScript…
我希望我刚开始使用TypeScript时早就知道了……
🤔问题 (🤔 The problem)
We all know how TypeScript can get slow in VS Code.
我们都知道TypeScript如何在VS Code中变慢 。
Ever found yourself waiting for the compiler to catch up with you as you type new code or fix errors?
您是否曾经发现自己在等待编译器在键入新代码或修复错误时赶上您?
This quickly gets frustrating, slowing down your feedback loops (and fast feedback loops are great to keep you happy and motivated!).
这很快会令人沮丧, 放慢了您的反馈循环 (而快速的反馈循环非常有助于保持您的快乐和动力!)。
使TypeScript更快地工作 (Make TypeScript work faster)
Here’s the trick:Run a separate TypeScript process in watch mode in a terminal tab. Keep it running as you write code — it’ll respond to changes and highlight errors a lot faster compared to VSCode.
诀窍在于: 在终端选项卡中的监视模式下运行单独的TypeScript进程。 与VSCode相比,在编写代码时使其保持运行状态-它可以响应更改并突出显示错误。
In my experience, the difference can be striking (see the screenshot). It seems to depend on the project and npm libs it’s using, but the general pattern is pretty consistent across different projects and TS versions I worked with.
以我的经验,差异可能是惊人的(请参见屏幕截图)。 它似乎取决于所使用的项目和npm库,但一般模式在我使用过的不同项目和TS版本之间是相当一致的。
Here’s how to set it up for your TypeScript project, step-by-step:
以下是逐步为您的TypeScript项目进行设置的方法:
- Add these 2 NPM scripts to your package.json: 将这两个NPM脚本添加到package.json中:
"scripts": {
...
"typecheck": "tsc",
"typecheck:watch": "tsc -w"
...
}
2. Now run npm run typecheck:watch
in a terminal tab (I like to do it in VSCode’s Terminal panel).
2.现在在终端选项卡中运行npm run typecheck:watch
(我喜欢在VSCode的“终端”面板中执行此操作)。
This starts a separate TypeScript process in the watch mode.
这将在监视模式下启动一个单独的TypeScript进程。
It’ll take some time to start, but it’ll be much faster to re-compile your code incrementally as you change your code.
这将需要一些时间来开始,但是随着更改代码,以增量方式重新编译代码会更快。
3. Use npm run typechek
if only need to do the check once. It’ll run faster than the watch mode.
3.如果只需要检查一次,请使用npm run typechek
。 它的运行速度将比观看模式快。
I find it handy e.g. before deploying to make sure the build will be succesful.
我觉得很方便,例如在进行部署之前,以确保构建成功。
it就是这样! (🙌 That’s it!)
I hope this tip will help you to become a more efficient and happier developer (it certainly helped me).
我希望这个技巧将帮助您成为一个更高效,更快乐的开发人员(它肯定对我有帮助)。
Please share your own experiences — did it help you to speed up your workflow?
请分享您自己的经验-这是否有助于您加快工作流程?
翻译自: https://medium.com/swlh/speed-up-your-typescript-vscode-workflow-in-1-minute-2e3c505e008b
vscode 打字计数