【发布时间】:2022-06-28 11:49:27
【问题描述】:
假设我有一个这样的界面:
interface Foo {
[barKey: string]: boolean;
}
// or as a type
type Foo = {
[barKey: string]: boolean;
}
然后我用这个类型初始化一个变量:
const myObj: Foo = {
"hello": false,
"world": true,
}
当我将鼠标悬停在它上面时,如何让编辑器(VSCode/IntellIJ/任何支持 JSDoc 的)拾取 JSDoc 作为键?我尝试过这样的事情:
/**
* A cool interface
*/
interface Foo {
/**
* Some hints about the property
*/
[barKey: string]: boolean;
}
不幸的是,这不起作用,我也尝试过这样的:
/**
* A cool interface
*/
interface Foo {
[
/**
* Some hints about the property
*/
barKey: string
]: boolean
}
但是没有成功,有什么办法可以做到吗?
TL;DR:如果从指定键类型的接口派生,如何记录每个对象键,以便编辑器在将鼠标悬停在键上时拾取它?
【问题讨论】:
标签: typescript jsdoc