在我的Vite + Vue 3 + Typescript项目中,我已经配置了 vue-tsc 在我开发时以观看模式运行。我将与 volar 一起使用。现在,我一方面将所有TS错误都印在控制台中,这就是我想要的。另一方面,我有 vue-tsc 的额外错误,但我没有 volar 。
例如,
我有一个错误,说 state.month 不能分配给 date ,但它是 date 。
vue-tsc
组件, volar 不显示该错误
在组件中显示该错误“> 状态。如您所见, state.month 是日期
有人可以帮我吗?我错过了什么吗?
In my Vite + Vue 3 + TypeScript project I have configured vue-tsc to run in watch mode while I am developing. I use VS Code with Volar. Now on one hand I have all my TS errors printed in the console which is what I was looking for. On the other hand I have extra errors from vue-tsc, but I don't have them from Volar.
For example,
I have one error saying that state.month is not assignable to type Date, but it is Date.
vue-tsc

component, volar does not showing that error

state in the component. As you see, state.month is Date

Could someone help me, please? Did I missed something?
发布评论
评论(2)
Project的 package.json 中的打字稿版本和VSCODE中的TypeScript版本不同。那导致了这些奇怪的错误。当我将 package.json 中的版本更新为同一版本的版本时,VSCODE的所有错误都消失了。
The version of TypeScript in project's package.json and the version of TypeScript in VSCode were different. That was causing these weird errors. When I had updated the version in package.json to the same version VSCode has all errors were gone.
要检查的另一件事是您的VUE-TSC软件包是最新的。 Volar是VS代码扩展名,随着时间的推移会自动更新,而Vue-TSC是NPM软件包,因此NPM将其锁定到版本,并且可能已过时。
那是我的解决方案。
获取最新的&保存为开发,运行
npm i -d vue -tsc@最新
。Volar存储库中的参考:
https://github.com/johnsoncodehk/volar/volar/volar/sissues/1205
Another thing to check is that your vue-tsc package is up to date. Volar is a VS Code extension and gets auto-updated over time, while vue-tsc is an npm package, so npm will lock it to a version and it could get outdated.
That was the solution for me.
To get the latest & save for dev, run
npm i -D vue-tsc@latest
.Reference in the Volar repo:
https://github.com/johnsoncodehk/volar/issues/1205