@fastify/error
Advanced tools
Comparing version 3.1.0 to 3.2.0
{ | ||
"name": "@fastify/error", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"description": "A small utility, used by Fastify itself, for generating consistent error objects across your codebase and plugins.", | ||
@@ -32,3 +32,3 @@ "main": "index.js", | ||
"tap": "^16.0.0", | ||
"tsd": "^0.24.1" | ||
"tsd": "^0.25.0" | ||
}, | ||
@@ -35,0 +35,0 @@ "tsd": { |
@@ -1,3 +0,6 @@ | ||
type CreateError = (code: string, message: string, statusCode?: number, Base?: Error) => createError.FastifyErrorConstructor | ||
declare function createError<C extends string, SC extends number>(code: C, message: string, statusCode: SC, Base?: Error): createError.FastifyErrorConstructor<{ code: C; statusCode: SC }>; | ||
declare function createError<C extends string>(code: C, message: string, statusCode?: number, Base?: Error): createError.FastifyErrorConstructor<{ code: C; }>; | ||
type CreateError = typeof createError; | ||
declare namespace createError { | ||
@@ -10,6 +13,6 @@ export interface FastifyError extends Error { | ||
export interface FastifyErrorConstructor { | ||
new(a?: any, b?: any, c?: any): FastifyError; | ||
(a?: any, b?: any, c?: any): FastifyError; | ||
readonly prototype: FastifyError; | ||
export interface FastifyErrorConstructor<E extends { code: string; statusCode?: number } = { code: string; statusCode?: number }> { | ||
new (a?: any, b?: any, c?: any): FastifyError & E; | ||
(a?: any, b?: any, c?: any): FastifyError & E; | ||
readonly prototype: FastifyError & E; | ||
} | ||
@@ -21,3 +24,2 @@ | ||
declare function createError(...params: Parameters<CreateError>): ReturnType<CreateError> | ||
export = createError |
@@ -5,7 +5,15 @@ import createError, { FastifyError, FastifyErrorConstructor } from '..' | ||
const CustomError = createError('ERROR_CODE', 'message') | ||
expectType<FastifyErrorConstructor>(CustomError) | ||
expectType<FastifyErrorConstructor<{ code: 'ERROR_CODE' }>>(CustomError) | ||
const err = new CustomError() | ||
expectType<FastifyError>(err) | ||
expectType<string>(err.code) | ||
expectType<FastifyError & { code: 'ERROR_CODE' }>(err) | ||
expectType<'ERROR_CODE'>(err.code) | ||
expectType<string>(err.message) | ||
expectType<number>(err.statusCode!) | ||
expectType<number>(err.statusCode!) | ||
const CustomTypedError = createError('OTHER_CODE', 'message', 400) | ||
expectType<FastifyErrorConstructor<{ code: 'OTHER_CODE'; statusCode: 400 }>>(CustomTypedError) | ||
const typed = new CustomTypedError() | ||
expectType<FastifyError & { code: 'OTHER_CODE'; statusCode: 400 }>(typed) | ||
expectType<'OTHER_CODE'>(typed.code) | ||
expectType<string>(typed.message) | ||
expectType<400>(typed.statusCode) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
11617
202
0