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<
4545> = T extends readonly any [ ]
4646 // Handle arrays or tuples.
4747 ? {
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+ > ;
5558 }
5659 : T extends Record < string , any >
5760 // Handle objects.
@@ -64,16 +67,19 @@ export type CamelCaseKeys<
6467 true ,
6568 ]
6669 ? 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 ] ;
7783 }
7884 // Return anything else as-is.
7985 : 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 */
22import { expectType , expectAssignable , expectNotType } from 'tsd' ;
33import camelcaseKeys , { type CamelCaseKeys } from './index.js' ;
44
@@ -350,3 +350,31 @@ expectNotType<InvalidConvertedExcludeObjectDataType>(
350350 exclude,
351351 } ) ,
352352) ;
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