Skip to content

Commit

Permalink
fix: Generic static This.
Browse files Browse the repository at this point in the history
  • Loading branch information
max-kahnt-keylight authored and lehni committed Sep 25, 2024
1 parent 85f0a10 commit bf76780
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion typings/objection/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,19 @@ declare namespace Objection {
new (): T;
}

interface PrototypeType<T> extends Function {
prototype: T;
}

interface ConstructorFunctionType<T = any> extends PrototypeType<T> {
new (...args: any[]): T;
}

// for internal use on generic static this deduction, copied from https://github.com/microsoft/TypeScript/issues/5863#issuecomment-1483978415
type ConstructorType<T = unknown, Static extends Record<string, any> = PrototypeType<T>> = (ConstructorFunctionType<T> | PrototypeType<T>) & {
[Key in keyof Static]: Static[Key];
};

export interface ModelConstructor<M extends Model> extends Constructor<M> {}

export interface ModelClass<M extends Model> extends ModelConstructor<M> {
Expand Down Expand Up @@ -1573,7 +1586,7 @@ declare namespace Objection {
): QueryBuilderType<M>;

static relatedQuery<M extends Model, K extends keyof M>(
this: Constructor<M>,
this: ConstructorType<M>,
relationName: K,
trxOrKnex?: TransactionOrKnex,
): ArrayRelatedQueryBuilder<M[K]>;
Expand Down

0 comments on commit bf76780

Please sign in to comment.