I have a variable storage, that stores all elements of type Person. So basically it is a dictionary with key URL and value PersonInstance:
let storage = {}
storage["localhost.com/person/1"] = new Person("John Wick");
Actually I could do it by writing:
/**
* @type {Object.<string, Person>}
*/
But VS Code Intellisense does not work in such case. Is there other way to document such object with unlimited number of keys in VS Code?
VScode's javascript intellisense is powered by TypeScript which unfortunatly does not currently support the Object.<string, Person> type syntax. Here's the bug tracking this.
You can work around this by using typescript syntax for the map:
/**
* @type {{ [key: string]: Person }}
*/
const storage = {}
which will improve the intellisense in vscode but is not a standard or widely supported jsdoc type.
Missing support for Object<string, T> has been added. However, be aware that casing matters!
Works
Object<string, T> where string is the index and T is the value type.
Does NOT work
object<string, T> - object MUST start with upper case: Object
Object<String, T> - String MUST be all lower case: string
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With