Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Code - how to document an object using JSDoc

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?

like image 431
Nursultan Zarlyk Avatar asked Nov 30 '25 06:11

Nursultan Zarlyk


2 Answers

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.

like image 161
Matt Bierner Avatar answered Dec 02 '25 18:12

Matt Bierner


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

like image 23
Jimmy Thomsen Avatar answered Dec 02 '25 19:12

Jimmy Thomsen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!