async getDetail(userId: number) {
const res = await this.userModel.findOne({
attributes: ['userId', 'username', 'wrongField1'], // should have an error for invalid field
where: {
userId,
wrongField2: 'here', // should have an error
},
raw: true,
});
// type of `res` is `UserModel | null`, excepted plain object `{ userId: number; username: string; } | null`
return res;
}
Versions
I'm submitting a ...
[x] bug report [ ] feature request
Actual behavior:
Type of attributes and where cannot be inferred by typescript.
And return type of query is always
MyModel
.Expected behavior:
Type inference can work.
Steps to reproduce:
Please see code below.
Related code:
user.model.ts
user.service.ts