diff --git a/index.d.ts b/index.d.ts index 5d7542a..1db6306 100644 --- a/index.d.ts +++ b/index.d.ts @@ -11,7 +11,7 @@ Return a default type if input type is nil. @template T - Input type. @template U - Default type. */ -type WithDefault = T extends undefined | void | null ? U : T; // eslint-disable-line @typescript-eslint/ban-types +type WithDefault = T extends undefined | void | null ? U : T; // eslint-disable-line @typescript-eslint/ban-types // TODO: Replace this with https://github.com/sindresorhus/type-fest/blob/main/source/includes.d.ts /** @@ -237,9 +237,9 @@ export default function camelcaseKeys< options?: OptionsType ): CamelCaseKeys< T, -WithDefault, -WithDefault, -WithDefault, -WithDefault, -WithDefault +WithDefault<'deep' extends keyof OptionsType ? OptionsType['deep'] : undefined, false>, +WithDefault<'pascalCase' extends keyof OptionsType ? OptionsType['pascalCase'] : undefined, false>, +WithDefault<'preserveConsecutiveUppercase' extends keyof OptionsType ? OptionsType['preserveConsecutiveUppercase'] : undefined, false>, +WithDefault<'exclude' extends keyof OptionsType ? OptionsType['exclude'] : undefined, EmptyTuple>, +WithDefault<'stopPaths' extends keyof OptionsType ? OptionsType['stopPaths'] : undefined, EmptyTuple> >; diff --git a/index.test-d.ts b/index.test-d.ts index 989d2c6..467d2b3 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -453,3 +453,21 @@ expectType<[ }), ]), ); + +// Test for function with inferred type +// eslint-disable-next-line @typescript-eslint/comma-dangle +function camelcaseKeysDeep< + T extends Record | readonly unknown[] +>(response: T): CamelCaseKeys { + return camelcaseKeys(response, {deep: true}); +} + +// eslint-disable-next-line @typescript-eslint/comma-dangle +function camelcaseKeysPascalCase< + T extends Record | readonly unknown[] +>(response: T): CamelCaseKeys { + return camelcaseKeys(response, {pascalCase: true}); +} + +expectType<{fooBar: {hogeHoge: string}}>(camelcaseKeysDeep({foo_bar: {hoge_hoge: 'hoge_hoge'}})); +expectType<{FooBar: string}>(camelcaseKeysPascalCase({foo_bar: 'foo_bar'}));