Skip to content

Commit

Permalink
types: add generics to isError and update DataT default generic p…
Browse files Browse the repository at this point in the history
…aram (#582)
  • Loading branch information
DamianGlowala authored Nov 24, 2023
1 parent e70cebe commit afc4183
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { hasProp } from "./utils/internal/object";
* This can be used to pass additional information about the error.
* @property {boolean} internal - Setting this property to `true` will mark the error as an internal error.
*/
export class H3Error<DataT = any> extends Error {
export class H3Error<DataT = unknown> extends Error {
static __h3_error__ = true;
statusCode = 500;
fatal = false;
Expand Down Expand Up @@ -64,16 +64,16 @@ export class H3Error<DataT = any> extends Error {
* @param input {string | (Partial<H3Error> & { status?: number; statusText?: string })} - The error message or an object containing error properties.
* @return {H3Error} - An instance of H3Error.
*/
export function createError<DataT = any>(
export function createError<DataT = unknown>(
input:
| string
| (Partial<H3Error<DataT>> & { status?: number; statusText?: string }),
): H3Error {
) {
if (typeof input === "string") {
return new H3Error<DataT>(input);
}

if (isError(input)) {
if (isError<DataT>(input)) {
return input;
}

Expand Down Expand Up @@ -177,6 +177,6 @@ export function sendError(
* @param input {*} - The input to check.
* @return {boolean} - Returns true if the input is an instance of H3Error, false otherwise.
*/
export function isError(input: any): input is H3Error {
export function isError<DataT = unknown>(input: any): input is H3Error<DataT> {
return input?.constructor?.__h3_error__ === true;
}

0 comments on commit afc4183

Please sign in to comment.