From 5c4b26e684da9e8d472f33c0837a1d83479a38ab Mon Sep 17 00:00:00 2001 From: Jesse McNelis Date: Tue, 6 Jun 2023 17:15:59 +1000 Subject: [PATCH] Fix type of Base argument to createError (#106) --- types/index.d.ts | 12 ++++++------ types/index.test-d.ts | 4 ++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index 3dd0873..e0d7a12 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,22 +1,22 @@ -declare function createError ( +declare function createError ( code: C, message: string, statusCode: SC, - Base?: Error + Base?: new () => Err ): createError.FastifyErrorConstructor<{ code: C, statusCode: SC }, Arg> -declare function createError ( +declare function createError ( code: C, message: string, statusCode?: number, - Base?: Error + Base?: new () => Err ): createError.FastifyErrorConstructor<{ code: C }, Arg> -declare function createError ( +declare function createError ( code: string, message: string, statusCode?: number, - Base?: Error + Base?: new () => Err ): createError.FastifyErrorConstructor<{ code: string }, Arg> type CreateError = typeof createError diff --git a/types/index.test-d.ts b/types/index.test-d.ts index a31a4b0..69eaaaf 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -65,3 +65,7 @@ expectError(new CustomTypedArgError6('a', 'b')) expectError(new CustomTypedArgError6('a', 'b', 'c')) CustomTypedArgError6('a', 'b', 'c', 'd') expectError(new CustomTypedArgError6('a', 'b', 'c', 'd', 'e')) + + +const CustomErrorWithErrorConstructor = createError('ERROR_CODE', 'message', 500, TypeError) +expectType>(CustomErrorWithErrorConstructor)