From bf76780aa23f83a4dfacb9f212355fde54be54e5 Mon Sep 17 00:00:00 2001 From: Max Kahnt Date: Fri, 6 Oct 2023 16:55:33 +0200 Subject: [PATCH] fix: Generic static This. --- typings/objection/index.d.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/typings/objection/index.d.ts b/typings/objection/index.d.ts index cfeb2049a..e0cf7d8a2 100644 --- a/typings/objection/index.d.ts +++ b/typings/objection/index.d.ts @@ -1423,6 +1423,19 @@ declare namespace Objection { new (): T; } + interface PrototypeType extends Function { + prototype: T; + } + + interface ConstructorFunctionType extends PrototypeType { + 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 = PrototypeType> = (ConstructorFunctionType | PrototypeType) & { + [Key in keyof Static]: Static[Key]; + }; + export interface ModelConstructor extends Constructor {} export interface ModelClass extends ModelConstructor { @@ -1573,7 +1586,7 @@ declare namespace Objection { ): QueryBuilderType; static relatedQuery( - this: Constructor, + this: ConstructorType, relationName: K, trxOrKnex?: TransactionOrKnex, ): ArrayRelatedQueryBuilder;