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.

https://stackoverflow.com/a/48455477/335583

It's 100% courtesy of https://stackoverflow.com/users/4408546/jeremy. 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 https://stackoverflow.com/a/48455477/335583 some love!

Top comments (0)