I have added // @ts-check
to a JavaScript file to use JSDoc. Suddenly I get errors in VS Code for functions included with a script tag:
<script src="imported-file.js"></script>
I can silence these by adding a lot of // @ts-ignore
(or maybe other ways?). But that would in my case just make JSDoc/TypeScript a burden.
So instead I wonder what types of ES6 includes/imports JSDoc/TypeScript can handle in VS Code. Can it handle module imports like this one below?
<script type="module" src="imported-file.js"></script>
Can it handle dynamic imports?
const myImportedModule = await import("imported-file.js");
Is there any good documentation about this?
EDIT:
I get the errors when I use the imported functions that are declared in "imported-file.js". They are in the global scope (as seen by JavaScript) just as Jared Smith understood it. The functions are not used in "imported-file.js" and I see no JSDoc errors there.
2
Answers
Thanks for your efforts. The solution I found easiest to work with was to just redefine the functions I needed from "imported-file.js". Let say I have a function called
myFun
in this file. I might then just add a statement like this:and then do a simple search and replace. This way I can avoid having a lot of
// @ts-ignore
for every place where I callmyFun
.If you want to add JSDoc and type checking just write a new function
TSmyFun
.I’m not sure I understand the problem you’re describing, but I think what you’ll want to do is use the
import
keyword when defining the type in your JSDocs. For exampleand then where it’s imported
If that isn’t what you’re looking for, then I’d need more details about what your specific setup looks like.