在 lib.d.ts 代码中使用 import inside for intellisense
Using import inside lib.d.ts for intellisense in Visual Studio Code
我的 JavaScript 项目中有一组自定义全局变量,我想使用 VSCode intellisense 来帮助我自动完成,如下所示:
auto completion for lol
经过一些谷歌搜索后,我找到了一种在与脚本相同的目录中使用 lib.d.ts
的方法。
如果 lib.d.ts
没有像这样引用其他文件:
// "lib.d.ts" file
class Lol {
f() : string;
}
declare const lol : Lol;
一切正常。
但是当我尝试将 Lol
class 移动到一个单独的文件中时,智能感知拒绝在我的脚本文件中显示 lol
变量:
// "lol.d.ts" file
export default class Lol {
f() : string;
}
// "lib.d.ts" file
import Lol from "./lol";
declare const lol : Lol;
有办法解决这个问题吗?
我想我找到了答案。
尽管脚本(声明样式)会污染全局范围并且不能使用import
,但模块可以做到这两点。
我没有使用 declare
,而是像这样切换到 export global
:
import Lol from "./lol";
declare global {
const lol : Lol;
}
我的 JavaScript 项目中有一组自定义全局变量,我想使用 VSCode intellisense 来帮助我自动完成,如下所示:
auto completion for lol
经过一些谷歌搜索后,我找到了一种在与脚本相同的目录中使用 lib.d.ts
的方法。
如果 lib.d.ts
没有像这样引用其他文件:
// "lib.d.ts" file
class Lol {
f() : string;
}
declare const lol : Lol;
一切正常。
但是当我尝试将 Lol
class 移动到一个单独的文件中时,智能感知拒绝在我的脚本文件中显示 lol
变量:
// "lol.d.ts" file
export default class Lol {
f() : string;
}
// "lib.d.ts" file
import Lol from "./lol";
declare const lol : Lol;
有办法解决这个问题吗?
我想我找到了答案。
尽管脚本(声明样式)会污染全局范围并且不能使用import
,但模块可以做到这两点。
我没有使用 declare
,而是像这样切换到 export global
:
import Lol from "./lol";
declare global {
const lol : Lol;
}