【问题标题】:Vscode Linting for property not work with .js but it works with .ts,Do you have this issue?Vscode Linting for property 不适用于 .js 但它适用于 .ts,你有这个问题吗?
【发布时间】:2021-03-21 16:14:12
【问题描述】:

当我在 VSCode 中输入例如 console.logsss.js 时没有出现错误,但是当我将其更改为 .ts 时出现错误,为什么这个简单的事情不适用于 .js 扩展?

【问题讨论】:

  • console.log() 正确
  • 我知道,但我故意写 console.logssss 看看为什么我没有错误,这与 console.log 无关,这是关于 .js 无法识别但 .ts 可以识别的方法和属性。

标签: javascript visual-studio-code eslint


【解决方案1】:

检查您的配置是否有 lint。如果您使用节点,请将其添加到package.json

"scripts": {
  ...,
  "lint": "eslint . --ext=js,jsx,ts",
  ...
}

【讨论】:

  • VSCode 不会通过 package.json 中的脚本自动 lint
【解决方案2】:

要让您的 JS 检查 TS 的方式,您必须:

  • 在工作区或用户设置中启用“checkJs”js/ts.implicitProjectConfig.checkJs(以前为 javascript.implicitProjectConfig.checkJs),
  • 在您的 JS 文件顶部使用 // @ts-check 魔术注释。

https://code.visualstudio.com/docs/languages/javascript#_type-checking

【讨论】:

    猜你喜欢
    • 2021-05-07
    • 2020-10-22
    • 2018-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-11
    • 2014-05-13
    • 2011-04-19
    相关资源
    最近更新 更多