Skip to content

Commit

Permalink
Fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante committed Jan 4, 2025
1 parent 7c1116d commit 94c10dd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion error-constructors.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Let `serialize-error` know about your custom error constructors so that when `{n
Warning: The constructor must work without any arguments or this function will throw.
*/
declare function addKnownErrorConstructor(constructor: ErrorConstructor): void;

type BaseErrorConstructor = new (message?: string, ...arguments_: unknown[]) => Error;
declare function addKnownErrorConstructor(constructor: BaseErrorConstructor): void;

export {addKnownErrorConstructor};
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {type Primitive, type JsonObject} from 'type-fest';

export {default as errorConstructors} from './error-constructors.js';
export {addKnownErrorConstructor} from './error-constructors.js';

export type ErrorObject = {
name?: string;
Expand Down
6 changes: 6 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {expectType, expectAssignable} from 'tsd';
import {
serializeError,
deserializeError,
addKnownErrorConstructor,
type ErrorObject,
type Options,
} from './index.js';
Expand All @@ -18,3 +19,8 @@ expectType<Error>(deserializeError({
name: 'name',
code: 'code',
}));

addKnownErrorConstructor(Error);

class CustomError extends Error {}
addKnownErrorConstructor(CustomError);

0 comments on commit 94c10dd

Please sign in to comment.