Vla*_*dei 3 intellisense javascript-intellisense jsdoc visual-studio-code es6-modules
我使用 Visual Studio Code 并将 IntelliSense 与 JsDoc 注释结合使用。我有两个带有类声明的模块:
/**
* This is Foo class
*/
export default class Foo {
constructor() {}
}
Run Code Online (Sandbox Code Playgroud)
和
/**
* This is Bar class
*/
export default class Bar {
constructor() {}
/**
* Init Bar from Foo
* @param {Foo} foo instance of Foo
* @returns {Bar}
*/
static initFromFoo(foo) {
return new Bar();
}
}
Run Code Online (Sandbox Code Playgroud)
类Bar用作Foo方法的参数initFromFoo,但 IntelliSense 不理解所@param Foo引用的内容class Foo并且无法正常工作并表示foo:any,
https://imgbbb.com/images/2019/09/24/image517c0ec9d1027ac9.png
如何才能让 IntelliSense 正常工作?
./foo。./bar/// <reference path="./foo">- 无效果jsconfig.json包含以下内容的文件:{
"compilerOptions": {
"target": "es6",
"allowSyntheticDefaultImports": true,
"checkJs": true
},
"exclude": [
"node_modules"
]
}
Run Code Online (Sandbox Code Playgroud)
也没有效果。它只是突出显示错误Cannot find name 'Foo'.ts(2304)
PS它看起来像与 ES6 模块相关的 IntelliSense 限制。因为如果我从两个文件中删除export/importIntelliSense 将按预期工作
https://i.ibb.co/CPL1gJC/image.png
https://i.ibb.co/xmXqzSk/image.png
PSS抱歉,图像链接我的存储库太低,无法发布图像。
可以通过import( path )语句导入类型。例如:
/**
* Init Bar from Foo
* @param {import('./foo').default} foo instance of Foo
* @returns {Bar}
*/
static initFromFoo(foo) {
return new Bar();
}
Run Code Online (Sandbox Code Playgroud)
或者
/**
* @typedef {import('./foo').default} Foo
*
* Init Bar from Foo
* @param {Foo} foo instance of Foo
* @returns {Bar}
*/
static initFromFoo(foo) {
return new Bar();
}
Run Code Online (Sandbox Code Playgroud)
PS这只是针对 Visual Studio Code 的 hack。它不是有效的 JsDoc。
| 归档时间: |
|
| 查看次数: |
2970 次 |
| 最近记录: |