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:
// "lib.d.ts" file class Lol { f() : string; } declare const lol : Lol;
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:
// "lol.d.ts" file export default class Lol { f() : string; }
// "lib.d.ts" file import Lol from "./lol"; declare const lol : Lol;
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:
import Lol from "./lol"; declare global { const lol : Lol; }