sequelize / sequelize-typescript

Decorators and some other features for sequelize

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Selecting Attributes from options of get methods doesn't update the typings

robwells124 opened this issue · comments

Issue

Selecting attributes doesn't update the typings of the return type of get methods and declares the attributes that aren't selected are defined when they shouldn't be.

Versions

  • sequelize:6.29.0
  • sequelize-typescript:2.1.5
  • typescript:4.9.5

Issue type

  • [] bug report
  • feature request

Actual behavior

When using any methods which would return a model using the AssociationGetOptions, when specifying what attributes of a model you want to return, the return type is that of the expected model. This means that fields in the model returned from using the model.$get() function for example can be undefined when the typings will say that they are defined.

Expected behavior

The typings should include a pick of the selected attributes, so that when you use any sequelize-typescript method that would return a model with a subset of the attributes, the typings should reflect that

Steps to reproduce

Use the example method: ** const associatedModel = await model.$get("associatedModel", {attributes: ["associatedField1"])** and the value of associatedModel.associatedField2 will be undefined even though the typings would suggest that it would be defined