Volar和Vue-TSC显示出不同的TS错误

发布于 2025-01-24 12:27:53 字数 932 浏览 2 评论 0 原文

在我的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
vue-tsc

component, volar does not showing that error
component, volar does not showing that error

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

Could someone help me, please? Did I missed something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无法回应 2025-01-31 12:27:53

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.

enter image description here

错々过的事 2025-01-31 12:27:53

要检查的另一件事是您的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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文