From 7928e0ffaefb139636faac1486d248534ad8cb2d Mon Sep 17 00:00:00 2001 From: MoSheikh Date: Wed, 24 Apr 2024 11:51:04 -0500 Subject: [PATCH] Export HttpError type (#159) * Export HttpError type * Add test --- lib/httpError.d.ts | 2 +- types/index.d.ts | 1 + types/index.test-d.ts | 10 +++++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/httpError.d.ts b/lib/httpError.d.ts index d8a8415..d3bed2c 100644 --- a/lib/httpError.d.ts +++ b/lib/httpError.d.ts @@ -1,4 +1,4 @@ -interface HttpError extends Error { +export interface HttpError extends Error { status: number; statusCode: number; expose: boolean; diff --git a/types/index.d.ts b/types/index.d.ts index b9dc129..2b99401 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -89,6 +89,7 @@ declare namespace fastifySensible { sharedSchemaId?: string; } + export type HttpError = Errors.HttpError; export type HttpErrors = Errors.HttpErrors; export type HttpErrorCodes = Errors.HttpErrorCodes; export type HttpErrorNames = Errors.HttpErrorNames; diff --git a/types/index.test-d.ts b/types/index.test-d.ts index c493baf..4496cdc 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -1,6 +1,6 @@ import { expectType, expectAssignable, expectError, expectNotAssignable } from 'tsd' import fastify from 'fastify' -import fastifySensible, { SensibleOptions, httpErrors } from '..' +import fastifySensible, { SensibleOptions, httpErrors, HttpError } from '..' const app = fastify() @@ -60,6 +60,14 @@ app.get('/', (req, reply) => { expectAssignable(app.httpErrors.createError(405, 'Method Not Allowed')) }) +app.get("/", (req, reply) => { + expectAssignable( + app.httpErrors.createError(405, "Method Not Allowed"), + ); + expectAssignable(app.httpErrors.badRequest()); +}); + + app.get('/', async (req, reply) => { expectAssignable(app.httpErrors.badRequest()) expectAssignable(app.httpErrors.unauthorized())