How to get VS Code to understand JSDOC's @typedef across multiple files

后端 未结 2 1806
自闭症患者
自闭症患者 2020-12-10 10:45

I want to specify a type in one file, and be able to reuse it in another one. I tried modules but it didn\'t work in VS Code. Is there any other solution? Just wanna have al

2条回答
  •  無奈伤痛
    2020-12-10 11:28

    Since TypeScript 2.9 which is embedded in the newer VS Codes, it is possible by using the import syntax in JSDoc, like so

    /**
     * @typedef {import("koa").Context} Context
     *
     * @typedef {Object} BodyparserOptions
     * @prop {(ctx: Context) => boolean} [detectJSON] Custom json request detect function. Default `null`.
     */
    

    Also VS Code should be picking up all types defined across the workspace.

提交回复
热议问题