Skip to content

Commit ece45c5

Browse files
authored
Fix CamelCaseKeys type (#78)
1 parent 12602fb commit ece45c5

2 files changed

Lines changed: 28 additions & 10 deletions

File tree

index.d.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,14 @@ type CamelCaseKeys<
6666
]
6767
? T[P]
6868
: [Deep] extends [true]
69-
? T[P] extends Record<string, any>
70-
? CamelCaseKeys<
71-
T[P],
72-
Deep,
73-
IsPascalCase,
74-
Exclude,
75-
StopPaths,
76-
AppendPath<Path, P>
77-
>
78-
: T[P]
69+
? CamelCaseKeys<
70+
T[P],
71+
Deep,
72+
IsPascalCase,
73+
Exclude,
74+
StopPaths,
75+
AppendPath<Path, P>
76+
>
7977
: T[P];
8078
}
8179
// Return anything else as-is.

index.test-d.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,26 @@ expectType<{fooBar: {fooBar: {fooBar: boolean}}}>(
3636
)
3737
);
3838

39+
interface ObjectOrUndefined {
40+
foo_bar: {
41+
foo_bar: {
42+
foo_bar: boolean;
43+
} | undefined;
44+
};
45+
}
46+
47+
const objectOrUndefined: ObjectOrUndefined = {
48+
foo_bar: {
49+
foo_bar: {
50+
foo_bar: true
51+
}
52+
}
53+
};
54+
55+
expectType<{fooBar: {fooBar: {fooBar: boolean} | undefined}}>(
56+
camelcaseKeys(objectOrUndefined, {deep: true})
57+
);
58+
3959
expectType<{FooBar: boolean}>(
4060
camelcaseKeys({'foo-bar': true}, {pascalCase: true})
4161
);

0 commit comments

Comments
 (0)