0

我正在使用 typegoose 来定义我的 mongoose/mongo-db 模型。typegoose 模型可能看起来像

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
}

(来自https://typegoose.github.io/typegoose/docs/decorators/prop/

我想重用这些类来获得各种打字稿接口,例如 api 调用。

我将如何剥离所有@prop(...)- 行并生成看起来像的东西

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

我想我想使用https://www.typescriptlang.org/docs/handbook/advanced-types.html#mapped-types但我不确定。

4

1 回答 1

0

new正如@ford04 已经说过的那样,当您想将其与或作为类型一起使用时,typegoose 的装饰器不会更改类

于 2020-03-03T16:26:00.140 回答