Type inference for static Model methods #189
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds type inference to most static methods on
Model
and its subclasses (create()
,findAll()
, etc) that previously required user-supplied generic parameters to correctly yield the correct return type.Person.findAll<Person>
simply becomesPerson.findAll()
, and TypeScript will automatically infer the correct return type. The old type signature will also continue to work. See microsoft/TypeScript#5863 for an explanation of what's going on under the hood that allows this to work.New overloads have been added to
Model.create<T extends Model<T>, A>(vals: A) : T
and its cousins, so thatModel.create<A>(vals: A) : T
may also be used in as a shorthand for when developers want to provide strict typings forA
, but don't need to override the automatic inference ofT
.Updates tests to run against the current version of Sequelize v4, and uses newer Bluebird type definitions (a milder version of #166 until we can figure out what to do there -- necessary because the older version had an inaccurate definition of
Promise.all
).