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

Add CamelCasedProps, CamelCasedPropsDeep etc. types #179

Merged
merged 42 commits into from Mar 22, 2021

Conversation

wwwzbwcom
Copy link
Contributor

Hello, I am using CamelCase etc. for API types converting, but found it difficult to write a well-defined CamelCasedProps and CamelCasedPropsDeep (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

@wwwzbwcom wwwzbwcom changed the title feat: add xxx-cased-props and xxx-cased-props-deep typings Add CamelCasedProps, CamelCasedPropsDeep etc. types Feb 4, 2021
@jamiebuilds
Copy link

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.

ts41/delimiter-cased-props-deep.d.ts Outdated Show resolved Hide resolved
ts41/delimiter-cased-props-deep.d.ts Outdated Show resolved Hide resolved
ts41/delimiter-cased-props.d.ts Outdated Show resolved Hide resolved
@sindresorhus
Copy link
Owner

You need to add the types to the readme.

@sindresorhus
Copy link
Owner

I would go with CamelCasedProps => CamelCasedProperties

@wwwzbwcom
Copy link
Contributor Author

@sindresorhus

You need to add the types to the readme.

I think they are already in REAME.md?

I would go with CamelCasedProps => CamelCasedProperties

renamed.

@wwwzbwcom
Copy link
Contributor Author

@sindresorhus Hello, is there any more changes needed for this PR?

@cluk3
Copy link

cluk3 commented Mar 9, 2021

looks great, would be nice to have it merged! We are already using SnakeCasedProperties within my company codebase (I copied it from the PR) and it works just fine. One thing this is is not supporting though is having consecutive upper case letters, testGUILabel would become test_g_u_i_label.

ts41/snake-cased-properties.d.ts Outdated Show resolved Hide resolved

@see SnakeCase
@see SnakeCasedPropertiesDeep
@example
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@example
@example

Copy link
Contributor Author

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> = {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const result: SnakeCasedProperties<User> = {
const result: SnakeCasedProperties<User> = {

ts41/snake-cased-properties.d.ts Outdated Show resolved Hide resolved
import {expectType} from 'tsd';

declare const foo: PascalCasedPropertiesDeep<{ helloWorld: { fooBar: string } }>;
expectType<{ HelloWorld: { FooBar: string } }>(foo);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expectType<{ HelloWorld: { FooBar: string } }>(foo);
expectType<{HelloWorld: {FooBar: string}}>(foo);

*/
export type CamelCasedPropertiesDeep<Value> = Value extends Function
? Value
: Value extends Array<infer U>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
: Value extends Array<infer U>
: Value extends ReadonlyArray<infer U>

?


```
*/
export type CamelCasedPropertiesDeep<Value> = Value extends Function
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export type CamelCasedPropertiesDeep<Value> = Value extends Function
export type CamelCasedPropertiesDeep<ValueType> = ValueType extends Function

Copy link
Contributor Author

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?

@sindresorhus
Copy link
Owner

Most of the nitpick changes I just commented on applies to all types, not just the ones I commented on.

@sindresorhus
Copy link
Owner

@kainiedziela Could you help review?

@kainiedziela
Copy link
Contributor

kainiedziela commented Mar 10, 2021

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 PartialDeep and it's test suite may clarify my ramblings.

@wwwzbwcom
Copy link
Contributor Author

Most of the nitpick changes I just commented on applies to all types, not just the ones I commented on.

@sindresorhus @kainiedziela
maybe we could add a .prettierconfig or code style lint guideline?
It's difficult to find out which style I should follow when contribute to it :(

@sindresorhus sindresorhus merged commit c043c25 into sindresorhus:main Mar 22, 2021
@sindresorhus
Copy link
Owner

Thanks :)

@jpilkahn
Copy link

Just came across this recent merge while consulting the documentation for unrelated reasons.
These types will be immensely useful! 😮

Thanks :)

Indeed.
To the both of you, @wwwzbwcom, @sindresorhus.

Having said that, may I suggest addition of equivalent property manipulation types for the inbuilt intrinsic string manipulation types?
Would be a natural fit, I feel.

Addendum, for the sake of completeness:
It is in the nature of collaborative spirit to include the offer to do the chore and open the PR myself (it'd just be a copy/paste/replace job anyway).

@sindresorhus
Copy link
Owner

Having said that, may I suggest addition of equivalent property manipulation types for the inbuilt intrinsic string manipulation types?

In general, it's better to open a new issue with your proposal (please elaborate more) than commenting on a done PR.

@jonjrodriguez
Copy link

How am I meant to import these types? When I try

import { CamelCasedPropertiesDeep } from 'type-fest/camel-cased-properties-deep'

it fails eslint with

Unable to resolve path to module 'type-fest/camel-cased-properties-deep'. eslintimport/no-unresolved)

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.

None yet

7 participants