Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 是否将类型指定为与新属性合并的接口?_Typescript_Interface - Fatal编程技术网

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。我是否可以在不创

在TypeScript中,是否有可能执行以下操作:

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 };
}

太好了,谢谢!