[英]Access dynamic property of an interface in Typescript
If I have an interface:如果我有一个界面:
export interface Person {
[key: string]: {
name: string;
alias: string;
active: string[];
values: string[];
};
}
If I want to access:如果我想访问:
{
name: string;
alias: string;
active: string[];
values: string[];
};
How can I do this?我怎样才能做到这一点? I tried
Person[keyof typeof Person]
but this does not work.我试过
Person[keyof typeof Person]
但这不起作用。
type X = Person[keyof Person];
Will return type:将返回类型:
type X = {
name: string;
alias: string;
active: string[];
values: string[];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.