【发布时间】:2022-01-07 12:49:29
【问题描述】:
我是这个打字稿的新手,nestjs。我想知道如何将Promise<any[]> 转换为Promise<MyEntity[]> 以便成功执行我创建的这段代码:
const usersfromTransaction = this.repoTransaction
.createQueryBuilder()
.select('user_id', 'id')
.distinctOn(['user_id'])
//.leftJoinAndSelect("user", "user")
.where('EXTRACT(YEAR FROM created_date)=EXTRACT(YEAR FROM NOW())')
.andWhere('extract(month from created_Date)=extract(month from now())')
.limit(10)
.getRawMany();
const users = this.repoUser.find(usersfromTransaction);
return user;
用户实体:
@Entity()
export class User {
@PrimaryGeneratedColumn('uuid')
id:string;
@Column({ nullable: true })
firstname:string;
@Column({ nullable: true })
lastname:string;
}
这行代码有错误this.repoUser.find(usersfromTransaction);
【问题讨论】:
-
repoUser的TS类型是什么? -
@MicaelLevi,先生更新了这个问题。
-
您没有显示
this.repoUser的来源。如果您使用了custom typeorm repository,则users的类型将为Promise<User[]>。先试试吧
标签: node.js typescript promise nestjs typeorm