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
chore: rename generics #2046
chore: rename generics #2046
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## next #2046 +/- ##
==========================================
- Coverage 99.60% 99.60% -0.01%
==========================================
Files 2605 2605
Lines 244951 244951
Branches 1257 1256 -1
==========================================
- Hits 243979 243974 -5
- Misses 945 950 +5
Partials 27 27
|
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.
I'm really torn on this one.
- I like using useful names
- I don't like the TName convention
- I don't think it adds value for methods that only do
T*
->T
- I think
TValue
/Value
does not transport any additional meaning overT
I watched the video and he explicitly mentions that As for TPrefixed: I see what argument he is trying to make, but if you cannot remember that |
T is prefixed with T :) I feel this is unnecessary. |
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.
I sadly can't reject the only request changes. Can I request to change everything back?
All of this is overkill. There are good situations to get verbose with your generic names. The ones changed in this PR do not belong to that category.
Me either 👍
Do you have a reason for that?
We have one example for when Yeah okay we could discuss this specific case and maybe just use better names from the start like
read above
These are really very generic (pun not intended) reasons without any real valuable arguments 😕 |
Addition: This PR aims to reduce the cognitive load of reading the code / using the methods |
Sure, it creates an arbitrary rule to name something in a special way inconsistently. EDIT: You could even use EDIT2: "prefix both types and interfaces with |
But what if you have an exported type
If the generic type is simple you don't need a full name in the first place. |
This! Excatly this!!! export interface IMyInterface {
// ... definition
}
export type TMyType = // definition I mean it cool, no? You just have to type |
I'm not tempted to drop proven ways of doing something just because of a single video without arguments for pro or con. Pro simple generics:
If you have a suggestion, we can discuss it. Currently the increased length of the name only takes more time to read till the extends clause that already tells me it is a |
Yes, the reasoning is a bit fussy, but IMO it is a valid point. |
Sure. Have a look at the implementation of a JS Generator: interface Generator<T = unknown, TReturn = any, TNext = unknown> extends Iterator<T, TReturn, TNext> {
// NOTE: 'next' is defined using a tuple to ensure we report the correct assignability errors in all places.
next(...args: [] | [TNext]): IteratorResult<T, TReturn>;
return(value: TReturn): IteratorResult<T, TReturn>;
throw(e: any): IteratorResult<T, TReturn>;
[Symbol.iterator](): Generator<T, TReturn, TNext>;
} This makes to have verbose names as we have multiple generics. Again, as long as you don't have multiple generic values you don't need to get creative. Please check the video again (time 1:59min to 2:01min):
|
@mattpocock May you give me/us some insight if this PR is what you wanted to achieve when creating your video How to Name your Types? |
No seriously: Reading more text for the same amount of information usually doesn't "reduce the cognitive load". |
8201742
to
d1402be
Compare
I would like to remember @xDivisionByZerox and @ST-DDT to read our Code of Conduct again. Line 5 in 5e421b0
Please don't blame me down or make assumptions about my potential Lines 9 to 13 in 5e421b0
Please try to write a bit more
For example we should prevent using exclamations like - I call cap. If you use a higher order type and don't know what the generic is supposed to be that's bad... like from your side, and you should probably not work with those types in that case.
+ If you use a higher order type, the generic template parameter is only supposed to transfer the given type the user is providing through it. However we should keep care on your side to not over-engineer types if they are getting to complex to used and the intention is not clear in the first place. This would have prevented me from getting attacked on a personal level. Please also think about PRs as a Pull Request which is indirectly always a proposal and needs to be accepted by the team/maintainers of a project, but can also get rejected / not merged. @ST-DDT was telling me the last weeks that I should not open issues for something when I directly can open a PR, because (and I agree with that) in a PR we can discuss on a per code-line level. I checked the template type of the TS definition So yes we should discuss two points:
|
Thanks for pointing this out. I'll try to improve on this. |
Team Decision
|
6c18585
to
da1fcc1
Compare
@faker-js/members @faker-js/maintainers Please write new review comments on each remaining rename with a reason why or why not it should be named T / not T, if it hurts you in your soul |
ce8ac16
to
eadf608
Compare
This has gotten stale over the last merges. |
eadf608
to
fabee15
Compare
fabee15
to
cd0084d
Compare
This PR renamed generics to a convention suggested by one of the TypeScript experts @mattpocock based on the YouTube video: https://www.youtube.com/watch?v=qA65QjWCl60
Also based on this poll (https://main.elk.zone/mas.to/@jvhellemond@mastodon.social/110124086297164650) by @jvhellemondextracted into #2049entries
are renamed toelements
when it is in the context of an array/setI only checked
src
folder