Skip to content

Commit afc4183

Browse files
types: add generics to isError and update DataT default generic param (#582)
1 parent e70cebe commit afc4183

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/error.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { hasProp } from "./utils/internal/object";
1919
* This can be used to pass additional information about the error.
2020
* @property {boolean} internal - Setting this property to `true` will mark the error as an internal error.
2121
*/
22-
export class H3Error<DataT = any> extends Error {
22+
export class H3Error<DataT = unknown> extends Error {
2323
static __h3_error__ = true;
2424
statusCode = 500;
2525
fatal = false;
@@ -64,16 +64,16 @@ export class H3Error<DataT = any> extends Error {
6464
* @param input {string | (Partial<H3Error> & { status?: number; statusText?: string })} - The error message or an object containing error properties.
6565
* @return {H3Error} - An instance of H3Error.
6666
*/
67-
export function createError<DataT = any>(
67+
export function createError<DataT = unknown>(
6868
input:
6969
| string
7070
| (Partial<H3Error<DataT>> & { status?: number; statusText?: string }),
71-
): H3Error {
71+
) {
7272
if (typeof input === "string") {
7373
return new H3Error<DataT>(input);
7474
}
7575

76-
if (isError(input)) {
76+
if (isError<DataT>(input)) {
7777
return input;
7878
}
7979

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

0 commit comments

Comments
 (0)