mongodb typescript类型检查

在node中,我使用的是mongodb客户端,findMany查询返回一个文档数组。

我真正需要的是,我应该能够确保返回的数组包含返回类型所期望的所有字段。

我已经定义了一个类型,例如Game,就像

export type Game {
 name: string;
 description: string;
 ...
} 

我的查询看起来像这样

const  games = (await this.games.find({}).toArray()) as Game[];

但我没有找到任何机制来确定响应是否包含Game类型所需的所有字段。

转载请注明出处:http://www.aqguliang.com/article/20230330/1238756.html