【发布时间】:2022-01-01 13:02:24
【问题描述】:
是否可以在类/接口中使用参数 T 的类型作为属性名?
export interface ISample<T> {
nameof(T) : T; <-- this property should have the name of the type T nameof(T)
otherProperties: any;
}
并像这样使用它:
const data: ISample<Houses>() = <something to construct the object>
console.log(data.houses)
所以houses 是由接口生成的data 的属性。
【问题讨论】:
标签: angular typescript generics typescript-generics