Typescript 删除具有映射类型的属性/类成员装饰器

Typescript 删除具有映射类型的属性/类成员装饰器,typescript,typegoose,Typescript,Typegoose,我正在使用typegoose定义我的mongoose/mongodb模型。一个典型的鹅模型可能看起来像 class Something { @prop({ required: true }) // this is now required in the schema public firstName!: string; @prop() // by default, a property is not required public lastName?: string; // u

我正在使用typegoose定义我的mongoose/mongodb模型。一个典型的鹅模型可能看起来像

class Something {
  @prop({ required: true }) // this is now required in the schema
  public firstName!: string;

  @prop() // by default, a property is not required
  public lastName?: string; // using the "?" marks the property as optional
}
(来自)

我想重用这些类来获得各种类型的脚本接口,例如api调用

如何剥离所有
@prop(…)
-行并生成类似的内容

interface Something {
  firstName: string,
  lastName?: string
}

我想我想使用,但我不确定。

正如@ford04已经指出的,当您想将类与
new
一起使用时,typegoose的装饰器不会更改该类,或者作为类型使用时,装饰器不应该影响TS编译时类型。例如,您可以通过
interface SomethingI扩展Something{}
Something
创建一个接口,然后像
type T1=keyof SomethingI//“firstName”|“lastName”