Skip to content

Commit bf76780

Browse files
max-kahnt-keylightlehni
authored andcommitted
fix: Generic static This.
1 parent 85f0a10 commit bf76780

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

typings/objection/index.d.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1423,6 +1423,19 @@ declare namespace Objection {
14231423
new (): T;
14241424
}
14251425

1426+
interface PrototypeType<T> extends Function {
1427+
prototype: T;
1428+
}
1429+
1430+
interface ConstructorFunctionType<T = any> extends PrototypeType<T> {
1431+
new (...args: any[]): T;
1432+
}
1433+
1434+
// for internal use on generic static this deduction, copied from https://github.com/microsoft/TypeScript/issues/5863#issuecomment-1483978415
1435+
type ConstructorType<T = unknown, Static extends Record<string, any> = PrototypeType<T>> = (ConstructorFunctionType<T> | PrototypeType<T>) & {
1436+
[Key in keyof Static]: Static[Key];
1437+
};
1438+
14261439
export interface ModelConstructor<M extends Model> extends Constructor<M> {}
14271440

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

15751588
static relatedQuery<M extends Model, K extends keyof M>(
1576-
this: Constructor<M>,
1589+
this: ConstructorType<M>,
15771590
relationName: K,
15781591
trxOrKnex?: TransactionOrKnex,
15791592
): ArrayRelatedQueryBuilder<M[K]>;

0 commit comments

Comments
 (0)