New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(types): return a usable type when using the sequelize.models lookup #11293
Conversation
906fd6a
to
c7b2669
Compare
Codecov Report
@@ Coverage Diff @@
## master #11293 +/- ##
==========================================
+ Coverage 95.58% 96.34% +0.76%
==========================================
Files 91 94 +3
Lines 8855 9057 +202
==========================================
+ Hits 8464 8726 +262
+ Misses 391 331 -60
Continue to review full report at Codecov.
|
this
value in getterMethods and setterMethodsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks ok, but we are looking to deprecate .models
eventually and I would discourage the use of .models
in the future for type safety.
Yeah, FWIW, I wouldn't mind if we added some more guidance on how to best use Sequelize in a typesafe manner, particularly with regard to model definitions. A bunch of the tricks that folks normally use to manage associations without introducing cyclical dependencies don't quite work in the TS world. |
@schmod What kind of tricks are you referring to? Can you show an example? (No rush, and not relevant to this PR) |
🎉 This PR is included in version 5.13.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Pull Request check-list
Please make sure to review and check all of these items:
npm run test
ornpm run test-DIALECT
pass with this change (including linting)?Description of change
Currently, looking up model classes via the
sequelize.models
interface does not yield an object with a usable type signature (for reasons that I admittedly do not entirely understand).Static functions such as
findAll
andbelongsTo
do not work on the values pulled off ofsequelize.models
, presumably because these methods use theModelCtor
"hack" to infer the correct return type.It appears that these methods can be called if
sequelize.models
is redefined to containModelCtor
s instead oftypeof Model
.