Typing with JSDoc3 an immutable object that uses generic keys is not well recognized in WebStorm

Viewed 109

I need help for typing with JSDoc3 an Immutable Object with generic keys because WebStorm is always complaining. Maybe I am wrong, please tell me.

Basically, typing an object with generic keys can be written as bellow

/** @typedef {Object<string,number>} myObject */

My object is Immutable, so I have created more JSDoc to cover some Immutable functions:

/**
 * @typedef {Object} ImmutableObject
 * @property {function} set
 * @property {function} setIn 
 */

Also my keys are in an enum, so more JSDoc

/**
 * @enum
 */
const SOME_KEYS= {KEY1: 'key1', KEY2:'key2'}

Then I put all together:

/** @typedef {ImmutableObject<SOME_KEYS,number>} myImmutableObject */

Despite all my efforts, WebStorm always complains that the function does not exists when I use an immutable function declared on an object type with myImmutableObject!

Here is a screenshot made from WebStorm 2020 (same on 2019):

screenshot made from WebStorm 2020

However, ImutableObject type work well when used "alone", here is a screenshot made from WebStorm 2020:

screenshot made from WebStorm 2020

1 Answers

Extending typedefs is not currently supported, please follow WEB-34403 and linked tickets for updates

Related