Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.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 - Fatal编程技术网

Typescript 类型脚本声明合并,如何取消合并?

Typescript 类型脚本声明合并,如何取消合并?,typescript,Typescript,我有下一个Typescript声明: import { Collection, Entity, IEntity, OneToMany, PrimaryKey, Property } from "mikro-orm"; import { ObjectId } from "mongodb"; import { LocationModel } from "./locationModel"; @Entity({ collection: "business" }) export class Busine

我有下一个Typescript声明:

import { Collection, Entity, IEntity, OneToMany, PrimaryKey, Property } from "mikro-orm";
import { ObjectId } from "mongodb";
import { LocationModel } from "./locationModel";

@Entity({ collection: "business" })
export class BusinessModel {
    @PrimaryKey()
    public _id!: ObjectId;

    @Property()
    public name!: string;

    @Property()
    public description!: string;

    @OneToMany({ entity: () => LocationModel, fk: "business" })
    public locations: Collection<LocationModel> = new Collection(this);
}

export interface BusinessModel extends IEntity<string> { }
import{Collection,Entity,IEntity,OneToMany,PrimaryKey,Property}来自“mikro-orm”;
从“mongodb”导入{ObjectId};
从“/LocationModel”导入{LocationModel};
@实体({集合:“业务”})
出口级商业模式{
@PrimaryKey()
public _id!:ObjectId;
@财产()
公共名称!:字符串;
@财产()
公共描述!:字符串;
@OneToMany({实体:()=>LocationModel,fk:“业务”})
公共场所:集合=新集合(本);
}
导出接口业务模型扩展了{}
现在,我怎样才能解开它们?要获取等效于以下内容的接口或数据类型:

export interface BusinessEntity {
    _id: ObjectId;
    name: string;
    description: string;
    locations: Collection<LocationModel>; 
}
导出接口业务实体{
_id:ObjectId;
名称:字符串;
描述:字符串;
地点:收集;
}

< /代码> 我无法访问您使用的类型/装饰器/模块,因此如果以下任何一个产生错误,您可以考虑将问题中的代码编辑为.< /p>
你可以试着通过以下方式来区分这些类型

type BusinessEntity = 
  Pick<BusinessModel, Exclude<keyof BusinessModel, keyof IEntity<string>>>

希望有帮助;祝你好运

你的解决方案有效。但我终于选择了你的建议,似乎我更清楚了。谢谢
@Entity({ collection: "business" })
export class BusinessEntity {
  @PrimaryKey()
  public _id!: ObjectId;

  @Property()
  public name!: string;

  @Property()
  public description!: string;

  @OneToMany({ entity: () => LocationModel, fk: "business" })
  public locations: Collection<LocationModel> = new Collection(this);
}

export class BusinessModel extends BusinessEntity { }
export interface BusinessModel extends IEntity<string> { }