DEV Community

Molly Crendraven
Molly Crendraven

Posted on

Using JSDoc in VSCode Without Import()

Look, It's another click-bait title. Guess what? It gets even worse. This isn't even my nugget of information.

It's 100% courtesy of For real, please go show that post some love.

This is more for me, and to try that whole "share as you learn" concept I'm really bad at.

Now that I've got all my disclamers covered...

I must be the only person on the planet who really doesn't like Microsoft's style of JSDoc support in VSCode. Because whenever I look for "Make JSDoc work with Intelisense" I get "just use import() in the tag!"

Ok, but there's a problem. import() is strictly a Microsoft thing, and is not valid JSDoc. JSDoc crashes when it sees it. Plus, it's ugly. Why it doesn't support module: like the docs say is the way? 🤷

But, if you don't use import(), VSCode will mark eveything as "any".

Unless... you happen to have stumbled, after years of searching, on this answer:

Export your interfaces and types normally, using a .d.ts file. Then, at the end of the file, add "export as namespace YOUR_NAMESPACE_HERE" New you can access them in any file as a property of the namespace.

And it works! Please, go show some love!

Top comments (0)