Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using interface defined in JSDoc in Typescript

I'm trying to setup TypeScript on a JS codebase with allowJs and checkJs

I have a JSDoc that uses an interface as a parameter type:

 * @param {IPlugin[]|IPlugin} plugins plugin instance(s).

In the same file, I have the interface defined via JSDoc:

/**
 * Plugin extension hooks.
 * @interface IPlugin
 * @since 2.1.0
 */

This looks like valid JSDoc to me. However, TypeScript is failing on it:

src/core/core.plugins.js:243:13 - error TS2304: Cannot find name 'IPlugin'.

243 * @param {IPlugin[]|IPlugin} plugins plugin instance(s).

Any ideas how I get this to work?

like image 402
Ben McCann Avatar asked Oct 27 '25 05:10

Ben McCann


1 Answers

@interface is not supported by Typescript: https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html#supported-jsdoc

It is suggested to use d.ts files instead: https://github.com/microsoft/TypeScript/issues/33207#issuecomment-527680208

Might also be able to hack it by using @typedef: https://github.com/AlCalzone/ioBroker.js-controller/blob/9fbbb890290b07af5d9dfb7ae90bf92f2d0be178/lib/tools.js#L1329

like image 176
Ben McCann Avatar answered Oct 28 '25 19:10

Ben McCann