简体   繁体   English

如何在 Visual Studio Code 上的 Vue 文件中启用 JavaScript 类型检查?

[英]How do I enable JavaScript type checking in Vue files on Visual Studio Code?

I have found the settings in Visual Studio Code to enable type checking for JavaScript in JS files.我在 Visual Studio Code 中找到了启用 JS 文件中 JavaScript 类型检查的设置。 Such that: Bad code is highlighted and it also shows the reason why it's bad code这样:错误代码被突出显示,它也显示了它是错误代码的原因

This behavior does not occur for JavaScript code in Vue files. Vue 文件中的 JavaScript 代码不会发生此行为。 I have searched through all the settings in Visual Studio Code.我已经搜索了 Visual Studio Code 中的所有设置。 I have scoured the internet for any extension that can do this for me to no avail.我已经在互联网上搜索了任何可以为我做这件事的扩展都无济于事。

How can I make my Vue files type-check the JavaScript in them?如何让我的 Vue 文件类型检查其中的 JavaScript?

For best results I'd suggest starting a new project using vue-cli and selecting the options for TypeScript and ESLint.为了获得最佳结果,我建议使用vue-cli开始一个新项目并选择 TypeScript 和 ESLint 的选项。 You'll also need the ESLint extension for VS Code.您还需要 VS Code 的 ESLint 扩展。

Here's a helpful blog post showing the parts of this process.这是一篇有用的博客文章,展示了此过程的各个部分。

Once you have a nicely working setup with the clean project, then move the code over.一旦您对干净的项目进行了良好的设置,然后将代码移过来。 I suggest this because getting all the config right can be a mess with an existing project.我建议这样做,因为正确配置所有配置可能会使现有项目一团糟。

LOL.哈哈。 I found the answer.我找到了答案。 All I had to do was add //@ts-check directly underneath the script tag and type checking was enabled.我所要做的就是直接在脚本标签下面添加 //@ts-check 并启用类型检查。 So HAPPY,,!很高兴,,! Thank you, everyone, for your input谢谢大家,您的意见

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM