Skip to content

Commit

Permalink
Fix type of Base argument to createError (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
jessta authored Jun 6, 2023
1 parent 137a6eb commit 5c4b26e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 6 additions & 6 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
declare function createError<C extends string, SC extends number, Arg extends unknown[] = [any?, any?, any?]> (
declare function createError<C extends string, SC extends number, Arg extends unknown[] = [any?, any?, any?], Err extends Error = Error> (
code: C,
message: string,
statusCode: SC,
Base?: Error
Base?: new () => Err
): createError.FastifyErrorConstructor<{ code: C, statusCode: SC }, Arg>

declare function createError<C extends string, Arg extends unknown[] = [any?, any?, any?]> (
declare function createError<C extends string, Arg extends unknown[] = [any?, any?, any?], Err extends Error = Error> (
code: C,
message: string,
statusCode?: number,
Base?: Error
Base?: new () => Err
): createError.FastifyErrorConstructor<{ code: C }, Arg>

declare function createError<Arg extends unknown[] = [any?, any?, any?]> (
declare function createError<Arg extends unknown[] = [any?, any?, any?], Err extends Error = Error> (
code: string,
message: string,
statusCode?: number,
Base?: Error
Base?: new () => Err
): createError.FastifyErrorConstructor<{ code: string }, Arg>

type CreateError = typeof createError
Expand Down
4 changes: 4 additions & 0 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<FastifyErrorConstructor<{ code: 'ERROR_CODE', statusCode: 500 }>>(CustomErrorWithErrorConstructor)

0 comments on commit 5c4b26e

Please sign in to comment.