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
Add CamelCasedProps
, CamelCasedPropsDeep
etc. types
#179
Conversation
CamelCasedProps
, CamelCasedPropsDeep
etc. types
We were just talking about wanting something like this in type-fest. This would make the built-in casing types far more useful. I think API type conversions are one of the more common use cases and you're generally talking about object properties there. |
You need to add the types to the readme. |
I would go with |
I think they are already in
renamed. |
@sindresorhus Hello, is there any more changes needed for this PR? |
looks great, would be nice to have it merged! We are already using |
|
||
@see SnakeCase | ||
@see SnakeCasedPropertiesDeep | ||
@example |
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.
@example | |
@example | |
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.
SnakeCased
don't have a newline after @example
, which style should follow?
userId: number; | ||
userName: string; | ||
} | ||
const result: SnakeCasedProperties<User> = { |
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.
const result: SnakeCasedProperties<User> = { | |
const result: SnakeCasedProperties<User> = { |
import {expectType} from 'tsd'; | ||
|
||
declare const foo: PascalCasedPropertiesDeep<{ helloWorld: { fooBar: string } }>; | ||
expectType<{ HelloWorld: { FooBar: string } }>(foo); |
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.
expectType<{ HelloWorld: { FooBar: string } }>(foo); | |
expectType<{HelloWorld: {FooBar: string}}>(foo); |
*/ | ||
export type CamelCasedPropertiesDeep<Value> = Value extends Function | ||
? Value | ||
: Value extends Array<infer U> |
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.
: Value extends Array<infer U> | |
: Value extends ReadonlyArray<infer U> |
?
|
||
``` | ||
*/ | ||
export type CamelCasedPropertiesDeep<Value> = Value extends Function |
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.
export type CamelCasedPropertiesDeep<Value> = Value extends Function | |
export type CamelCasedPropertiesDeep<ValueType> = ValueType extends Function |
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.
CamelCased<>
used Value
, Is it better to keep it same as CamelCased
?
Most of the nitpick changes I just commented on applies to all types, not just the ones I commented on. |
@kainiedziela Could you help review? |
So usually what we do with -deep types is that we ensure that as many different cases are covered - not only function, objects and arrays, but maps and sets and readonly types of all of those things as well. While I understand that in this instance perhaps being so dilligent about covering all cases may not make as much sense I do think that we should document exactly what get's recursed into what does not. @wwwzbwcom looking at |
@sindresorhus @kainiedziela |
Thanks :) |
Just came across this recent merge while consulting the documentation for unrelated reasons.
Indeed. Having said that, may I suggest addition of equivalent property manipulation types for the inbuilt intrinsic string manipulation types? Addendum, for the sake of completeness: |
In general, it's better to open a new issue with your proposal (please elaborate more) than commenting on a done PR. |
How am I meant to import these types? When I try import { CamelCasedPropertiesDeep } from 'type-fest/camel-cased-properties-deep' it fails
|
Hello, I am using
CamelCase
etc. for API types converting, but found it difficult to write a well-definedCamelCasedProps
andCamelCasedPropsDeep
(which can convert array etc.), so I add these type to make type-fest naming converting easier to use.I think these types are similar and connected, so I add them in one PR