interface Table<T> {
[index: string]: T;
}
interface IPeople {
sex:string;
age:number;
name:string;
}
class People implements IPeople {
public sex:string = "man";
public age:number = 30;
public name:string = "老王"
}
class Chinese extends People {
public country:string = "ch"
}
class A {
public p:Table<IPeople> = {}
public fun<T extends People>(param:T):T{
return this.p[param]
}
}
提示报错
Type 'T' cannot be used to index type 'IPeople'.
不知道你这个
fun
是干什么用的因为你这个
p
是Table
所以索引用string
就行了