You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using extends Promise<R> as is being done in Objection's QueryBuilder typings is incorrect, according to how Objection is implemented. The QueryBuilder does not actually have the Promise.prototype in its prototype chain. Saying that it does causes tsc to believe properties exist on them that actually don't.
Notably, the native Promise prototype in Node (as well as most browsers) implements finally. Objection's QueryBuilders do not implement finally, nor do they implement any other functionality of that type besides then and catch.
I'm not simply suggesting that they should add finally. The use of extends here is simply incorrect and will produce more problems like this if and when any additional functionality is added to the native Promise type.
TypeScript provides the PromiseLike<R> interface for these situations, though that interface only
requires then and not catch. What QueryBuilders implement as far as promise functionality is concerned is this:
I will have a PR up shortly to make the necessary corrections, but this will be a breaking change for dependents written in TypeScript. Promise and PromiseLike (even CatchablePromiseLike) are not interchangeable, specifically because Promises implement additional stuff.
I understand there might me some unwillingness to make this change, but it is causing some problems for some people, notably me, as discussed here.
It's not something that should be rushed into, of course, but it would be nice to have this for the next major release.
The text was updated successfully, but these errors were encountered:
Using
extends Promise<R>
as is being done in Objection's QueryBuilder typings is incorrect, according to how Objection is implemented. The QueryBuilder does not actually have thePromise.prototype
in its prototype chain. Saying that it does causes tsc to believe properties exist on them that actually don't.Notably, the native Promise prototype in Node (as well as most browsers) implements finally. Objection's QueryBuilders do not implement
finally
, nor do they implement any other functionality of that type besidesthen
andcatch
.I'm not simply suggesting that they should add
finally
. The use ofextends
here is simply incorrect and will produce more problems like this if and when any additional functionality is added to the native Promise type.TypeScript provides the
PromiseLike<R>
interface for these situations, though that interface onlyrequires
then
and notcatch
. What QueryBuilders implement as far as promise functionality is concerned is this:I will have a PR up shortly to make the necessary corrections, but this will be a breaking change for dependents written in TypeScript. Promise and PromiseLike (even CatchablePromiseLike) are not interchangeable, specifically because Promises implement additional stuff.
I understand there might me some unwillingness to make this change, but it is causing some problems for some people, notably me, as discussed here.
It's not something that should be rushed into, of course, but it would be nice to have this for the next major release.
The text was updated successfully, but these errors were encountered: