File tree Expand file tree Collapse file tree 2 files changed +52
-18
lines changed Expand file tree Collapse file tree 2 files changed +52
-18
lines changed Original file line number Diff line number Diff line change @@ -45,13 +45,16 @@ export type CamelCaseKeys<
45
45
> = T extends readonly any [ ]
46
46
// Handle arrays or tuples.
47
47
? {
48
- [ P in keyof T ] : CamelCaseKeys <
49
- T [ P ] ,
50
- Deep ,
51
- IsPascalCase ,
52
- Exclude ,
53
- StopPaths
54
- > ;
48
+ // eslint-disable-next-line @typescript-eslint/ban-types
49
+ [ P in keyof T ] : { } extends CamelCaseKeys < T [ P ] >
50
+ ? T [ P ]
51
+ : CamelCaseKeys <
52
+ T [ P ] ,
53
+ Deep ,
54
+ IsPascalCase ,
55
+ Exclude ,
56
+ StopPaths
57
+ > ;
55
58
}
56
59
: T extends Record < string , any >
57
60
// Handle objects.
@@ -64,16 +67,19 @@ export type CamelCaseKeys<
64
67
true ,
65
68
]
66
69
? T [ P ]
67
- : [ Deep ] extends [ true ]
68
- ? CamelCaseKeys <
69
- T [ P ] ,
70
- Deep ,
71
- IsPascalCase ,
72
- Exclude ,
73
- StopPaths ,
74
- AppendPath < Path , P & string >
75
- >
76
- : T [ P ] ;
70
+ // eslint-disable-next-line @typescript-eslint/ban-types
71
+ : { } extends CamelCaseKeys < T [ P ] >
72
+ ? T [ P ]
73
+ : [ Deep ] extends [ true ]
74
+ ? CamelCaseKeys <
75
+ T [ P ] ,
76
+ Deep ,
77
+ IsPascalCase ,
78
+ Exclude ,
79
+ StopPaths ,
80
+ AppendPath < Path , P & string >
81
+ >
82
+ : T [ P ] ;
77
83
}
78
84
// Return anything else as-is.
79
85
: T ;
Original file line number Diff line number Diff line change 1
- /* eslint-disable @typescript-eslint/naming-convention */
1
+ /* eslint-disable @typescript-eslint/naming-convention, @typescript-eslint/indent */
2
2
import { expectType , expectAssignable , expectNotType } from 'tsd' ;
3
3
import camelcaseKeys , { type CamelCaseKeys } from './index.js' ;
4
4
@@ -350,3 +350,31 @@ expectNotType<InvalidConvertedExcludeObjectDataType>(
350
350
exclude,
351
351
} ) ,
352
352
) ;
353
+
354
+ expectType < {
355
+ funcFoo : ( ) => 'foo' ;
356
+ recordBar : { foo : string } ;
357
+ promiseBaz : Promise < unknown > ;
358
+ } > (
359
+ camelcaseKeys ( {
360
+ func_foo : ( ) => 'foo' ,
361
+ record_bar : { foo : 'bar' } ,
362
+ promise_baz : new Promise ( resolve => {
363
+ resolve ( true ) ;
364
+ } ) ,
365
+ } ) ,
366
+ ) ;
367
+
368
+ expectType < [
369
+ ( ) => 'foo' ,
370
+ { foo : string } ,
371
+ Promise < unknown > ,
372
+ ] > (
373
+ camelcaseKeys ( [
374
+ ( ) => 'foo' ,
375
+ { foo : 'bar' } ,
376
+ new Promise ( resolve => {
377
+ resolve ( true ) ;
378
+ } ) ,
379
+ ] ) ,
380
+ ) ;
You can’t perform that action at this time.
0 commit comments