Objection.js: Since 2.0 `ModelClass` does not have `#query` In typings

Created on 4 Jan 2020  路  5Comments  路  Source: Vincit/objection.js

In version 1.x ModelClass<T> works fine.
image

Now, in 2.0+ an typing error is thrown on the exact same code.

image

Is this expected, what would be the correct usage?

Thanks a lot 馃槃

Most helpful comment

@francocorreasosa @patricklol22 a new version 2.1.0 has been released and the old ModelClass type is back. Let me know if you run in to trouble with it.

All 5 comments

The ModelClass type isn't really useful in 2.0 anymore. It's used only internally. You can use typeof NoteModel

@koskimas Sounds good, thanks a lot!

since I have updated to version 2 I have a similar error

image

I used to have a workaround with ModelClass<any> inside the constructor but with typeof Model i get 'Model' is assignable to the constraint of type 'M', but 'M' could be instantiated with a different subtype of constraint 'Model'.

@patricklol22 you would need to use typeof M but typescript doesn't support it. We may need to bring back the old ModelClass type for this. I haven't considered generic usage like this.

@francocorreasosa @patricklol22 a new version 2.1.0 has been released and the old ModelClass type is back. Let me know if you run in to trouble with it.

Was this page helpful?
0 / 5 - 0 ratings