我对打字稿很陌生,很难找到一些关于keyof
. 如果你有
export interface someClassProps<T extends object> {
/*
Lets assume T look is an object that looks something like:
T = {"name": "",
"val": NaN,
"active": false}
*/
A: Array<T>; // an array of objects
B: keyof T; // What type is this? Is just a type of object or is it the keys of T?
C: keyof Array<T>[0]; // Is this the keys of T?
D: keyof Array<T> // Is this type object?
}
你得到什么类型的B
或C
?我希望从中得到一种类型keyof
是 the will be name | val | active
。我是否正在寻找一种看起来像B
,C
或完全不同的方法?
或者有一种简单的方法可以打印类型keyof
吗?这会让我弄清楚这一点。