-
Notifications
You must be signed in to change notification settings - Fork 20
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
Add types declaration file, update objection to ^2.2.0 #20
base: master
Are you sure you want to change the base?
Conversation
class SDQueryBuilder<M extends Model> { | ||
SingleQueryBuilderType: SDQueryBuilder<M>; | ||
|
||
delete(): this['SingleQueryBuilderType'] & M['QueryBuilderType']['SingleQueryBuilderType']; | ||
hardDelete(): this['SingleQueryBuilderType'] & M['QueryBuilderType']['SingleQueryBuilderType']; | ||
undelete(): this['SingleQueryBuilderType'] & M['QueryBuilderType']['SingleQueryBuilderType']; | ||
whereDeleted(): this['SingleQueryBuilderType'] & M['QueryBuilderType']['SingleQueryBuilderType']; | ||
whereNotDeleted(): this['SingleQueryBuilderType'] & M['QueryBuilderType']['SingleQueryBuilderType']; | ||
} |
There 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.
I manually used your PR in my project, but I made the types for the SDQueryBuilder class as such:
import { Model, QueryBuilder } from 'objection';
class SDQueryBuilder<M extends Model, R = M[]> extends QueryBuilder<M, R> {
ArrayQueryBuilderType!: SDQueryBuilder<M>;
NumberQueryBuilderType!: SDQueryBuilder<M, number>;
delete(): this['NumberQueryBuilderType'];
hardDelete(): this['NumberQueryBuilderType'];
undelete(): this['NumberQueryBuilderType'];
whereDeleted(): this['ArrayQueryBuilderType'];
whereNotDeleted(): this['ArrayQueryBuilderType'];
}
// And changed SDInstance to:
interface SDInstance<T extends typeof Model> {
QueryBuilderType: SDQueryBuilder<this>;
}
There 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 cleaner. If it works then all's good 👍
There 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.
Just updated the comment, we didn't need the SingleQueryBuilderType
and the PageQueryBuilderType
so I removed them. We would need them if the plugin added methods like .findById()
and .page()
.
.delete()
, .hardDelete()
and undelete()
internally use .patch()
, which returns the NumberQueryBuilder
.
.whereDeleted()
and .whereNotDeleted()
internally use .where()
and .whereNot()
, which returns the ArrayQueryBuilder
.
Resolves #17. As mentioned in the issue, updating
objection
to a more recent version is required to allow TypeScript support. It works fine from my own tests working from the code in the Readme but if there are any issues then please let me know.