简体   繁体   English

IntelliJ IDEA 中 JSDoc 类型的 map-like object

[英]JSDoc type of map-like object in IntelliJ IDEA

Following assignment分配后

/**
 * @type {Object<string, string>}
 */
const x = { a: 'b' };

IDEA marks with warning带有警告的 IDEA 标记

Initializer type {a: string} is not assignable to variable type Object<string, string>初始化器类型 {a: string} 不可分配给变量类型 Object<string, string>

IDEA中的警告截图

What is the correct way to type-annotate a map-like object so that IDEA can understand it?类型注释 map-like object 以便 IDEA 能够理解它的正确方法是什么?

Using Object<string, string> is a right way to go , and使用Object<string, string>go 的正确方法,并且

/**
 * @type {Object<string, string>}
 */
const x = { a: "1" };

as well as

/**
 * @type {Object.<string, string>}
 */
const x = { a: "1" };

work fine for me in 2021.2 You can also use the Google Closure Compiler record types like在 2021.2 对我来说工作正常您还可以使用Google Closure Compiler record类型,例如

*
 * @type {{a: string}}
 */
const y = { a: "1" };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM