简体   繁体   English

提示类定义所在的 VSCode

[英]Hint VSCode where the class definition is

tI have this code:我有这个代码:

const Gatherer = require('../gatherer');

class MetaRobots extends Gatherer {
  /**
   * @param {{driver: !Driver}} options Run options
   …
}

module.exports = MetaRobots;

VSCode highlights Driver (inside jsdoc) because it's unable to find its definition. VSCode 突出显示Driver (在 jsdoc 中),因为它无法找到它的定义。 However, the definition of that class is in the same project:但是,该类的定义在同一个项目中:

class Driver {
…
}

module.exports = Driver;

Importing Driver in the MetaRobots file ( const Driver = require('../../driver'); ) fixes the issue, but then I have an unused import.MetaRobots文件中导入Driverconst Driver = require('../../driver'); )解决了这个问题,但我有一个未使用的导入。

Can't find definition of Driver 😢找不到 Driver 的定义😢 找不到驱动程序的定义

Can find definition of Driver, but Driver import is unused 😢可以找到Driver的定义,但是Driver import没有用😢 可以找到Driver的定义,但是Driver import没有使用

Is there any way I can hint VSCode about definition of Driver w/o importing it?有什么方法可以提示 VSCode 关于Driver定义而无需导入它?

[EDIT] Additional info: [编辑] 附加信息:

It seems it's not a problem with the vscode itself but rather an issue with the TypeScript server running underneath.这似乎不是 vscode 本身的问题,而是运行在下面的 TypeScript 服务器的问题。

Unfortunately, currently you need to import Connection in the driver.js file for IntelliSense to pick up the types properly.不幸的是,目前您需要在driver.js文件中导入Connection以便 IntelliSense 正确选择类型。 It's being discussed on how it should be solved.正在讨论如何解决。 There is also an issue describing very similar case.还有一个问题描述了非常相似的案例。

You can try experimenting with type definitions files and UMD modules but it might not work.您可以尝试使用类型定义文件和 UMD 模块进行试验,但它可能不起作用。

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

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