Skip to content

Commit

Permalink
🏷️ Add type definitions for constructorHandlers option
Browse files Browse the repository at this point in the history
Adds TypeScript definitions for #40
  • Loading branch information
alecgibson committed Jun 12, 2024
1 parent 228fc35 commit 7991bbb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ declare namespace rfdc {
interface Options {
proto?: boolean;
circles?: boolean;
constructorHandlers?: ConstructorHandlerConfig[];
}
}
type Constructor<T> = {new(...args: any[]): T};
type ConstructorHandlerConfig<T = any> = [Constructor<T>, (o: T) => T];

declare function rfdc(options?: rfdc.Options): <T>(input: T) => T;

Expand Down
6 changes: 6 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ const clone = rfdc();

expectType<number>(clone(5));
expectType<{ lorem: string }>(clone({ lorem: "ipsum" }));

const cloneHandlers = rfdc({
constructorHandlers: [
[RegExp, (o) => new RegExp(o)],
],
})

0 comments on commit 7991bbb

Please sign in to comment.