-
Notifications
You must be signed in to change notification settings - Fork 511
fix(toCamelCaseKeys): improve toCamelCaseKeys type inference for uppercase keys #1538
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
base: main
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a type inference issue in toCamelCaseKeys where uppercase keys (e.g., FIRST_NAME, LAST) were incorrectly typed at the type level (e.g., lAST instead of last), even though the runtime behavior was correct. The fix updates the PascalToCamel utility type to detect fully uppercase strings and convert them to fully lowercase, aligning TypeScript types with runtime behavior.
- Updated the
PascalToCameltype to handle uppercase keys by fully lowercasing them when all characters are uppercase - Added comprehensive test coverage for uppercase keys, PascalCase keys, and non-plain object handling
- Updated documentation in all four supported languages (English, Korean, Japanese, Chinese) to clarify the behavior
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/object/toCamelCaseKeys.ts | Updated PascalToCamel type to detect and handle uppercase keys by fully lowercasing them |
| src/object/toCamelCaseKeys.spec.ts | Added three new test cases covering uppercase keys, PascalCase keys, and non-plain object handling with both runtime and type-level assertions |
| docs/reference/object/toCamelCaseKeys.md | Added behavior documentation and example for uppercase and PascalCase key conversion |
| docs/ko/reference/object/toCamelCaseKeys.md | Added Korean translation of behavior documentation and example |
| docs/ja/reference/object/toCamelCaseKeys.md | Added Japanese translation of behavior documentation and example |
| docs/zh_hans/reference/object/toCamelCaseKeys.md | Added Chinese (Simplified) translation of behavior documentation and example |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1538 +/- ##
=======================================
Coverage 99.97% 99.97%
=======================================
Files 474 474
Lines 4492 4493 +1
Branches 1313 1313
=======================================
+ Hits 4491 4492 +1
Misses 1 1 🚀 New features to boost your workflow:
|
close #1537
Descriptio
This PR fixes a mismatch between the runtime behavior and TypeScript types of
toCamelCaseKeys, especially for uppercase keys (e.g.FIRST_NAME,LAST).At runtime,
camelCase('LAST')correctly returnslast, but the type-level transformation previously inferredlAST. This caused TypeScript to report incorrect key names in the resulting object type.The PR also extends the test suite and documentation so that the behavior of
toCamelCaseKeysis clearly specified and protected against regressions.Changes
PascalToCamelutility type to:S extends Uppercase<S>) and transform them to fully lowercase (Lowercase<S>), aligning with the runtimecamelCasebehavior.PascalCasekeys (e.g.UserId→userId,ApiToken→apiToken).{ FIRST_NAME: 'JinHo', LAST: 'Yeom' }→{ firstName: 'JinHo', last: 'Yeom' }Date,Map,Set, etc.toCamelCaseKeysdocumentation with:snake_case,PascalCase, and uppercase keys are all converted tocamelCase.Motivation
toCamelCaseKeys, especially in strongly-typed codebases.LAST→lAST), which was confusing for consumers and could lead to subtle type errors.PascalToCameltype with howcamelCaseactually behaves, we make the API more predictable and safer to use, especially when dealing with API responses or legacy schemas that use uppercase keys.Breaking Changes
toCamelCaseKeysis unchanged.lASTare now correctly inferred aslast.