Typescript 是否将类型指定为与新属性合并的接口?
在TypeScript中,是否有可能执行以下操作:Typescript 是否将类型指定为与新属性合并的接口?,typescript,interface,Typescript,Interface,在TypeScript中,是否有可能执行以下操作: interface IPerson { name: string; } interface Test { something: number; personWithVersion: IPerson & (version: string); // is something like that possible? } personWithVersion应具有来自IPerson的属性和另一个属性version。我是否可以在不创
interface IPerson {
name: string;
}
interface Test {
something: number;
personWithVersion: IPerson & (version: string); // is something like that possible?
}
personWithVersion
应具有来自IPerson
的属性和另一个属性version
。我是否可以在不创建新接口的情况下指定此项,或者我是否必须创建一个新接口,如IPersonWithVersion
,然后扩展IPerson
?尝试以下操作:
interface IPerson {
name: string;
}
interface Test {
something: number;
personWithVersion: IPerson & { version: string };
}
太好了,谢谢!