sequelize-typescript
sequelize-typescript copied to clipboard
typescript type infer cannot work accurately
Versions
- sequelize: 5.21.5
- sequelize-typescript: 1.1.0
- typescript: 3.8.3
- @types/bluebird: 3.5.30
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
@Table({
tableName: 'user',
freezeTableName: true,
timestamps: false,
})
export default class UserModel extends Model<UserModel> {
@Column({
field: 'user_id',
primaryKey: true,
autoIncrement: true,
type: DataType.INTEGER,
})
userId!: number;
@Column({
field: 'user_name',
type: DataType.STRING(50),
})
username!: string;
}
user.service.ts
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;
}
@dreamerblue the same problem
Same issue - anyone have anything?
Same problem
Its there a solution for this?? I am facing the same problem...