【问题标题】:VS Code: "go to definition" not working on exported classVS Code:“转到定义”不适用于导出的类
【发布时间】:2018-12-22 22:54:47
【问题描述】:

我无法在exported 类上单击属性类型注释时使用 VS Code 中的“转到定义”功能。这是一个例子:

//Core.js
export default class Core { constructor() {} }

//Engine.js
export default class Engine{
    /** @type {Core} core */
    constructor(core) {
        /** @type {Core} */            
        this.core = core;
    }
} 

//index.js
import Core from './Core';
import Engine from './Engine';

const core = new Core();
const engine = new Engine(core);

当我在 Engine.js 中并想通过单击注释 {Core} 转到 Core.js 类时,它不起作用。如果我使用“转到定义”,VS 代码会显示:没有找到 'Core' 的定义。

我做错了什么? 甚至可能吗? 谢谢你

【问题讨论】:

    标签: javascript annotations visual-studio-code definition


    【解决方案1】:

    使用@typedef 注释将类型“导入”到文件中,如下所示:

    /** @typedef {import('./Core').default} Core */
    
    export default class Engine{
        /** @type {Core} core */
        constructor(core) {
            /** @type {Core} */            
            this.core = core;
        }
    }
    

    【讨论】:

      【解决方案2】:

      请向我们展示您的项目文件层次结构。很可能您没有从项目的根目录开始定义导入。

      import Page from 'components/Page'; //1
      
      
      import Page from './../components/Page'; //2
      

      1 不适合我,但 2 可以。

      【讨论】:

        猜你喜欢
        • 2020-02-05
        • 2018-11-30
        • 1970-01-01
        • 2018-01-17
        • 2019-08-04
        • 2021-12-17
        • 1970-01-01
        • 1970-01-01
        • 2020-11-07
        相关资源
        最近更新 更多