diff --git a/index.d.ts b/index.d.ts index e1e9416..3ed41af 100644 --- a/index.d.ts +++ b/index.d.ts @@ -45,13 +45,15 @@ export type CamelCaseKeys< > = T extends readonly any[] // Handle arrays or tuples. ? { - [P in keyof T]: CamelCaseKeys< - T[P], - Deep, - IsPascalCase, - Exclude, - StopPaths - >; + [P in keyof T]: Record extends CamelCaseKeys + ? T[P] + : CamelCaseKeys< + T[P], + Deep, + IsPascalCase, + Exclude, + StopPaths + >; } : T extends Record // Handle objects. @@ -64,16 +66,18 @@ export type CamelCaseKeys< true, ] ? T[P] - : [Deep] extends [true] - ? CamelCaseKeys< - T[P], - Deep, - IsPascalCase, - Exclude, - StopPaths, - AppendPath - > - : T[P]; + : Record extends CamelCaseKeys + ? T[P] + : [Deep] extends [true] + ? CamelCaseKeys< + T[P], + Deep, + IsPascalCase, + Exclude, + StopPaths, + AppendPath + > + : T[P]; } // Return anything else as-is. : T; diff --git a/index.test-d.ts b/index.test-d.ts index f2b2f99..2c11b45 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -350,3 +350,27 @@ expectNotType( exclude, }), ); + +expectType<{ + funcFoo: () => 'foo'; + recordBar: Record; + promiseBaz: Promise; +}>(camelcaseKeys({ + func_foo: () => 'foo', + record_bar: {foo: 'bar'}, + promise_baz: new Promise(resolve => { + resolve(true); + }), + })); + +expectType<[ + () => 'foo', + Record, + Promise, +]>(camelcaseKeys([ + () => 'foo', + {foo: 'bar'}, + new Promise(resolve => { + resolve(true); + }), + ])); diff --git a/package.json b/package.json index 32293ef..919d4ed 100644 --- a/package.json +++ b/package.json @@ -1,77 +1,77 @@ { - "name": "camelcase-keys", - "version": "8.0.0", - "description": "Convert object keys to camel case", - "license": "MIT", - "repository": "sindresorhus/camelcase-keys", - "funding": "https://github.com/sponsors/sindresorhus", - "author": { - "name": "Sindre Sorhus", - "email": "sindresorhus@gmail.com", - "url": "https://sindresorhus.com" - }, - "type": "module", - "exports": "./index.js", - "types": "./index.d.ts", - "engines": { - "node": ">=14.16" - }, - "scripts": { - "test": "xo && ava && tsd", - "bench": "matcha bench/bench.js" - }, - "files": [ - "index.js", - "index.d.ts" - ], - "keywords": [ - "map", - "obj", - "object", - "key", - "keys", - "value", - "values", - "val", - "iterate", - "camelcase", - "camel-case", - "camel", - "case", - "dash", - "hyphen", - "dot", - "underscore", - "separator", - "string", - "text", - "convert", - "pascalcase", - "pascal-case", - "deep", - "recurse", - "recursive" - ], - "dependencies": { - "camelcase": "^7.0.0", - "map-obj": "^4.3.0", - "quick-lru": "^6.1.1", - "type-fest": "^2.13.0" - }, - "devDependencies": { - "ava": "^4.3.0", - "matcha": "^0.7.0", - "tsd": "^0.20.0", - "xo": "^0.49.0" - }, - "xo": { - "overrides": [ - { - "files": "bench/bench.js", - "rules": { - "import/no-unresolved": "off" - } - } - ] - } -} + "name": "camelcase-keys", + "version": "8.0.0", + "description": "Convert object keys to camel case", + "license": "MIT", + "repository": "sindresorhus/camelcase-keys", + "funding": "https://github.com/sponsors/sindresorhus", + "author": { + "name": "Sindre Sorhus", + "email": "sindresorhus@gmail.com", + "url": "https://sindresorhus.com" + }, + "type": "module", + "exports": "./index.js", + "types": "./index.d.ts", + "engines": { + "node": ">=14.16" + }, + "scripts": { + "test": "xo && ava && tsd", + "bench": "matcha bench/bench.js" + }, + "files": [ + "index.js", + "index.d.ts" + ], + "keywords": [ + "map", + "obj", + "object", + "key", + "keys", + "value", + "values", + "val", + "iterate", + "camelcase", + "camel-case", + "camel", + "case", + "dash", + "hyphen", + "dot", + "underscore", + "separator", + "string", + "text", + "convert", + "pascalcase", + "pascal-case", + "deep", + "recurse", + "recursive" + ], + "dependencies": { + "camelcase": "^7.0.0", + "map-obj": "^4.3.0", + "quick-lru": "^6.1.1", + "type-fest": "^2.13.0" + }, + "devDependencies": { + "ava": "^4.3.0", + "matcha": "^0.7.0", + "tsd": "^0.20.0", + "xo": "^0.49.0" + }, + "xo": { + "overrides": [ + { + "files": "bench/bench.js", + "rules": { + "import/no-unresolved": "off" + } + } + ] + } +} \ No newline at end of file