-
Notifications
You must be signed in to change notification settings - Fork 30.5k
[@types/camelize] fixes types for camelize package #70145
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,14 +7,14 @@ type CamelCase<S extends string> = S extends `${infer FirstWord}${CamelSeparator | |
| ? `${Lowercase<FirstWord>}${Uppercase<SecondChar>}${CamelCase<Remaining>}` | ||
| : Lowercase<S>; | ||
|
|
||
| type Camelize<T> = { | ||
| [K in keyof T as CamelCase<string & K>]: T[K] extends {} ? Camelize<T[K]> : T[K]; | ||
| }; | ||
|
|
||
| declare function camelize<T>(obj: T): T extends string ? CamelCase<T> | ||
| type Camelize<T> = T extends Date ? T | ||
| : T extends RegExp ? T | ||
| : T extends Date ? T | ||
| : T extends {} ? Camelize<T> | ||
| : T extends Array<infer I> ? Array<Camelize<I>> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've also added support for arrays (these are handled separately in the original package as well) |
||
| : T extends object ? { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm changing here |
||
| [K in keyof T as CamelCase<string & K>]: Camelize<T[K]>; | ||
| } | ||
| : T; | ||
|
|
||
| declare function camelize<T>(obj: T): T extends string ? CamelCase<T> : Camelize<T>; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. top level exported function only checks whether the provided argument is string |
||
|
|
||
| export = camelize; | ||
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.
check for
RegExpandDatehappens in thewalkfunction which is also run on nested fields. Moving this condition to theCamelizetype