JSDoc typedef in a separate file

2019-03-14 15:45发布

Can I define all custom types in a separate file (e.g. types.jsdoc), so that they can be reused throughout the application? What's the right way to do it?

/**
 * 2d coordinates.
 * @typedef {Object} Coordinates
 * @property {Number} x - Coordinate x.
 * @property {Number} y - Coordinate y.
 */

标签: jsdoc
2条回答
三岁会撩人
2楼-- · 2019-03-14 16:10

I just tried with VSCode and it works only if the separate file is opened in the editor. If not, external typedefs are typed as any

查看更多
乱世女痞
3楼-- · 2019-03-14 16:18

I usually do something similar in my projects, the difference being I use the extension .js to name the file. Webstorm works perfectly and is able to check types and auto-complete just fine. It won't recognize the .jsdoc extension (I just checked), so stick to .js even if the file doesn't contain any code statement.

查看更多
登录 后发表回答