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

Handle CamelCase with non-literal strings #531

Merged
merged 1 commit into from Dec 25, 2022

Conversation

rayrw
Copy link
Contributor

@rayrw rayrw commented Dec 21, 2022

Fixes #513
Fixes #475

Hi there! I appreciate this library helping us handle a lot of common TypeScript operations!
Recently I encountered an issue and would like to propose a solution to that.

I'm using CamelCasedPropertiesDeep to transform the object's keys to camel case, with some of the proproties are just normal Record<string, ObjectType>.
In runtime, I have done an extra handling to prevent transforming in that layer. However, the type definition does not match this handling. I get { '': TransformedObjectType } in the type, but I was expecting { [x: string]: TransformedObjectType }.

I found that the cause was that currently CamelCase<string> is evaluated to ''.

Therefore, I'd like to suggest a way to handle it and support my use case.

My suggestion is adding another branch of conditional type checking if string extends Type, and only proceed to the main transforming logic if it is not.
I hope this makes sense and would love to hear back from you if it is not handling enough.
Thank you!

@rayrw rayrw requested a review from voxpelli as a code owner December 21, 2022 06:54
@sindresorhus sindresorhus merged commit 00b13f8 into sindresorhus:main Dec 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants