使用 vscode 在 .js 文件上 typescript

标签 typescript visual-studio-code

通常我想用 typescript 而不是 Flow 来写 .js 文件。我将 webpack 配置为在 js 扩展上使用 ts-loader,并且工作正常。我在 tsconfig 文件上使用 checkJs 并检查 js 文件。

但是,VS Code 在 js 文件上显示错误:

Type annotations can only be used in TypeScript files.

Screenshot of Error

如何在 VS Code 中消除该错误?

最佳答案

您不能在 js 文件中使用 typescript 类型声明。 (即使启用了 checkJS)

在 JS 文件上,您必须使用 JSDoc 注释。

/** @type {number} */
var x;

Typescript 会为您检查这些。

但我猜你要找的是一个 .ts 文件

关于使用 vscode 在 .js 文件上 typescript ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49362018/

相关文章:

typescript - 阻止 eslint 在 typescript 的非空断言运算符上窒息?

docker - VSCode/Intellij 中 docker 容器中 Tomcat/Wildfly 服务器的远程调试

typescript - Angular2、TypeScript 和 Visual Studio Code 绝对路径配置

windows-7 - 右键单击文件夹后不出现 Visual Studio Code "Open With Code"

javascript - 预期 typescript 错误 'module, class, interface, enum, import or statement'

typescript - 在 TypeScript 中推断接口(interface)属性类型

linux - 为什么 Visual Studio Code 想要访问我的 SSH 私钥?

jasmine - Intellisense 不适用于 VS Code 上的 Jasmine

typescript :使用静态内部类的类型

html - 如何使用 Typescript 在 React 中扩展 HTML 属性