Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: default value setting to correctly resolve function return types #117

Merged
merged 1 commit into from
Oct 17, 2023

Conversation

yutak23
Copy link
Contributor

@yutak23 yutak23 commented Oct 17, 2023

This ought to fix #116.

The problem lies in the generic type OptionsType.
For example, if pascalCase is not included in the options, the following type definition would result in the type being unknow.

OptionsType['pascalCase']; // unknown

Therefore, the type would be CamelCaseKeys<T, true, unknown, unknown, unknown, ""> as in the issue, resulting in a compile error.

With this fix, i change the type to be undefined when there is no key in the options, so the type WithDefault works correctly and the type of the default value part is the default value for each.

Specifically, it becomes CamelCaseKeys<T, true> when the options are as follows.

camelcaseKeys(response, {deep: true}); // CamelCaseKeys<T, true>

※The above without abbreviation would be CamelCaseKeys<T, true, false, false, [], [], ''>.

@sindresorhus sindresorhus merged commit 482bd84 into sindresorhus:main Oct 17, 2023
3 checks passed
@sindresorhus
Copy link
Owner

Thanks for the quick fix 🙏

@yutak23 yutak23 deleted the feature/fix-type-default branch October 17, 2023 08:25
@WoodyWoodsta
Copy link

Thank you @yutak23!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using function with inferred type does not resolve correct return type defaults
3 participants