我有一个变量storage,它存储Person 类型的所有元素。所以基本上它是一个包含键 URL 和值 PersonInstance 的字典:
let storage = {}
storage["localhost.com/person/1"] = new Person("John Wick");
实际上我可以这样写:
/**
* @type {Object.<string, Person>}
*/
但 VS Code Intellisense 在这种情况下不起作用。有没有其他方法可以在 VS Code 中使用无限数量的键来记录此类对象?
最佳答案
VScode 的 javascript intellisense 由 TypeScript 提供支持,遗憾的是目前不支持 Object.<string, Person>
类型语法。 Here's the bug tracking this .
您可以通过对 map 使用 typescript 语法来解决此问题:
/**
* @type {{ [key: string]: Person }}
*/
const storage = {}
这将改进 vscode 中的智能感知,但不是标准或广泛支持的 jsdoc 类型。
关于javascript - VS Code - 如何使用 JSDoc 记录对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44614847/