Skip to content

Commit 6330dc0

Browse files
authored
🏷️ Add type definitions for constructorHandlers option (#43)
Adds TypeScript definitions for #40
1 parent 228fc35 commit 6330dc0

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ declare namespace rfdc {
22
interface Options {
33
proto?: boolean;
44
circles?: boolean;
5+
constructorHandlers?: ConstructorHandlerConfig[];
56
}
67
}
8+
type Constructor<T> = {new(...args: any[]): T};
9+
type ConstructorHandlerConfig<T = any> = [Constructor<T>, (o: T) => T];
710

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

index.test-d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ const clone = rfdc();
55

66
expectType<number>(clone(5));
77
expectType<{ lorem: string }>(clone({ lorem: "ipsum" }));
8+
9+
const cloneHandlers = rfdc({
10+
constructorHandlers: [
11+
[RegExp, (o) => new RegExp(o)],
12+
],
13+
})

0 commit comments

Comments
 (0)