4

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?

1 Answer 1

4

@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

Sign up to request clarification or add additional context in comments.

1 Comment

I tried using @typedef it didn't work, but maybe in some previous/newer version of TypeScript.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.