似乎我在弹出预览中输入了正确的类型,但是,代码完成(intellisense)建议仅显示一个属性
id
。
接口不会从定义它们的文件中导出,但是,即使我导出它们,行为也没有改变。
在 WebStorm 中:
正确的类型提示:
编辑:
我有一个
Model
类,它采用 2 种类型的泛型:
export default class Model<TAttributes = unknown, TEmbeds = unknown> {
attributes: TAttributes & { id: number }
embeds: TEmbeds & {}
这个类然后用于
ApiResponse
:
export class ApiResponse<T extends Model> {
private readonly items: T[]
constructor(response: IApiResponse, model: { new(...args: any[]): T; } | null) {
this.items = model ? response.items.map(item => new model(item)) : response.items
getStatic(): (T['attributes'] & T['embeds'])[] {
const staticItems: (T['attributes'] & T['embeds'])[] = []
for (const item of this.items) {
const staticItem =
{
...item.attributes,
...item.embeds,
}
staticItems.push(staticItem)
}
return staticItems
}
}
当我从
getStatic()
方法访问数据时,我希望 WebStorm 显示模型接口的所有属性的建议,但是,只显示 id
。