Selecting Attributes from options of get methods doesn't update the typings
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
- [x] 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
Do you know if there is a workaround for this? I really want to work with attributes, and this makes it so much harder. I don't know why this isn't already a feature.
+1 on this one, I wonder how others are working around this limitation, I've found a few instances of us trying to access fields that weren't really there just because they were not fetched as part of attributes array, yet Typescript didn't catch this when typechecking!