我正在使用 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但我不确定。