Skip to content

Commit 5c4b26e

Browse files
authored
Fix type of Base argument to createError (#106)
1 parent 137a6eb commit 5c4b26e

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

types/index.d.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
declare function createError<C extends string, SC extends number, Arg extends unknown[] = [any?, any?, any?]> (
1+
declare function createError<C extends string, SC extends number, Arg extends unknown[] = [any?, any?, any?], Err extends Error = Error> (
22
code: C,
33
message: string,
44
statusCode: SC,
5-
Base?: Error
5+
Base?: new () => Err
66
): createError.FastifyErrorConstructor<{ code: C, statusCode: SC }, Arg>
77

8-
declare function createError<C extends string, Arg extends unknown[] = [any?, any?, any?]> (
8+
declare function createError<C extends string, Arg extends unknown[] = [any?, any?, any?], Err extends Error = Error> (
99
code: C,
1010
message: string,
1111
statusCode?: number,
12-
Base?: Error
12+
Base?: new () => Err
1313
): createError.FastifyErrorConstructor<{ code: C }, Arg>
1414

15-
declare function createError<Arg extends unknown[] = [any?, any?, any?]> (
15+
declare function createError<Arg extends unknown[] = [any?, any?, any?], Err extends Error = Error> (
1616
code: string,
1717
message: string,
1818
statusCode?: number,
19-
Base?: Error
19+
Base?: new () => Err
2020
): createError.FastifyErrorConstructor<{ code: string }, Arg>
2121

2222
type CreateError = typeof createError

types/index.test-d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,7 @@ expectError(new CustomTypedArgError6('a', 'b'))
6565
expectError(new CustomTypedArgError6('a', 'b', 'c'))
6666
CustomTypedArgError6('a', 'b', 'c', 'd')
6767
expectError(new CustomTypedArgError6('a', 'b', 'c', 'd', 'e'))
68+
69+
70+
const CustomErrorWithErrorConstructor = createError('ERROR_CODE', 'message', 500, TypeError)
71+
expectType<FastifyErrorConstructor<{ code: 'ERROR_CODE', statusCode: 500 }>>(CustomErrorWithErrorConstructor)

0 commit comments

Comments
 (0)