有没有办法让 VS Code 中的 JS 编辑器标记标识符为 unknown/any 类型(仅假定存在)?

Is there a way to make JS editor in VS Code mark identifiers with unknown/any type (which are only presumed to exist)?

当 pasting/moving 在 JS 中编码时,能够找到没有已知类型的 functions/variables 会很有用。它们的类型通常是未知的,因为可能缺少代码(或您可能希望在 TS/JSDoc 中添加的类型定义)。

目前,我必须将鼠标悬停在每个标识符上以检查它们是否具有已知类型。我现在的主题是Monokai,并没有做这个区分。

我想知道是否有某种 setting/theme/extension 让我很容易地看到什么时候标识符只是假定存在,没有保证(例如,外部全局变量或 属性)。我的意思是让这些标识符有不同的颜色,或者可能是 info/warning 下划线标记。我认为 NetBeans 可能具有类似这样的功能,因为我记得全局变量具有不同的颜色。

when an identifier is only presumed to exist, without guarantee - for example, an external global variable or property

这听起来更像是您在寻找未声明的 变量。由于现代 JavaScript 中良好的范围规则,这非常简单,并且默认情况下大多数 linters 会抱怨(并突出显示)这些。比如在eslint中取the no-undef rule.

Find functions/variables which have no known type. Their type is often unknown because of code that might be missing (or type definitions that you might want to add in TS/JSDoc).

这听起来更像是打字稿问题。但是,是的,有些工具会抱怨其类型未声明/也无法推断的变量。有关详细信息,请参阅

感谢 Bergi 为我指明了正确的方向!

为了在 JS 中得到这些错误,我必须做的只是添加一个 jsconfig.json.compilerOptions.checkJs: true。例如:

{
  "compilerOptions": {
    "noImplicitAny": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "strict": true,
    "checkJs": true,
    "target": "esnext"
  }
}