I have a set of custom global variables in my JavaScript project and I want to use VSCode intellisense to help me with auto completion like this:
After some googling I found a way to use lib.d.ts
in the same directory as the script.
If lib.d.ts
doesn’t refer other files like this:
JavaScript
x
7
1
// "lib.d.ts" file
2
class Lol {
3
f() : string;
4
}
5
6
declare const lol : Lol;
7
everything works fine.
But when I try to move Lol
class into a separate file the intellisense refuses to show the lol
variable in my script file:
JavaScript
1
5
1
// "lol.d.ts" file
2
export default class Lol {
3
f() : string;
4
}
5
JavaScript
1
5
1
// "lib.d.ts" file
2
import Lol from "./lol";
3
4
declare const lol : Lol;
5
Is there a way to fix this?
Advertisement
Answer
I think I found an answer.
Despite scripts (declare style) can pollute global scope and can’t use import
, modules can do both.
Instead of using declare
I switched to export global
like this:
JavaScript
1
6
1
import Lol from "./lol";
2
3
declare global {
4
const lol : Lol;
5
}
6