node.jstypescriptvisual-studio-codejsdoc

Where can I store JSDoc typedef information to share across projects?


I'm adding @typedef JSDoc comments to the top of Javascript files to help define types (really, so that I can take advantage of some of the typescript benefits without learning it all today).

Where can I store JSDoc typedef information to share across projects in VSCode?

For example, can I store this in some external file and then use it in multiple .js files?

/**
 * @typedef {Object} SomeType
 * @property {String} id
 */

Solution

  • You can put that code snippet in a .js file and then either add it to the files or include in each tsconfig.json file or use a reference directive:

    ///<reference path="path/to/shared-file.js" />
    

    (These are the same two options you have for TypeScript declaration files.) It gets a little more complicated if your shared file is an ES6 module (with top-level ES6 imports or exports); then you'll need to either import it or use import types.