“ Typecheck”是什么?使用VITE和TS在VUE项目中进行的NPM脚本?
我使用TypeScript创建了一个新的VUE项目,并通过
npm init vue@最新
在软件包文件中
"typecheck": "vue-tsc --noEmit -p tsconfig.vitest.json --composite false",
。我应该使用此脚本来确保我的代码很好吗? (例如QA工作流程)
I created a new Vue project using TypeScript and Vite via
npm init vue@latest
Inside the package.json file there is a typecheck script
"typecheck": "vue-tsc --noEmit -p tsconfig.vitest.json --composite false",
but I don't know its purpose. Should I use this script to ensure that my code is fine? ( E.g. for QA workflows )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Vite
Bundler不执行类型检查;因此,默认情况下 - 如果您的typescript
代码中有任何错误 -vite
不会像正常情况那样抱怨并将其转移(这是为什么它如此快的原因) 。“ typecheck”
脚本将按照其名称的建议进行,请检查.ts
and.vue 错误通过
vue-tsc -noemit
命令文件。重要的是要了解此脚本不会注意更改,只运行一次每个执行。但是,这是一个重要的脚本,应该尽可能地运行,尤其是作为CI/CD构建过程的一部分。
还值得注意的是,您可以将脚本的开始更改为
“ TSC -noemit
”到Typecheck.ts
专门。 ://vitejs.dev/guide/features.html#typescript“ rel =“ nofollow noreferrer”>文档。
Vite
bundler does not perform type checking; so by default - if there are any errors in yourTypeScript
code -Vite
will not complain and transpile it as normal (this is part of the reason why it is so fast).The
"typecheck"
script will do as it's name suggests, check for anyTypeScript
errors in your.ts
and.vue
files via thevue-tsc --noEmit
command. It is important to understand that this script will not watch for changes and only run onceper execution. Nevertheless, it is a vital script and should be run as much as possible, especially as part of your CI/CD build process.
It is also worth noting that you can change the start of the script to
"tsc --noEmit
to typecheck.ts
files exclusively.Ref to the documentation.