-
-
Notifications
You must be signed in to change notification settings - Fork 150
feature(u.distributiveomit): Add U.DistributiveOmit type #75
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
Conversation
I guess when its already under U namespace its ok to call it just Omit. Was using this a standalone type previously and had to name it differently - hence weirdo DistributiveOmit 😉 |
Hey @Andarist, thanks for your contrib'. I added Thanks! |
Hey @Andarist, I got an after thought I was thinking about your distributive
|
However, the Just leaving these notes to you, as we worked together on this |
I guess this is because those are not actually implemented using mapped types (?). But I actually don't know that much about how TS works in those more complex scenarios under the hood. You certainly have much broader knowledge about this stuff.
Yeah, I'm wondering why this works in a way it works by default 🤔
I appreciate it. |
They are mapped types ( type test = keyof ({a: 1, b: 2} | {a: 3, c: 4}) // 'a' Because of that, you'd only be able to pick the Also, the TypeScript team did not enable this by default because they wanted to leave the type distribution opt-in, it distributes by using
Unfortunately, we cannot simply replace |
Problem with TS is that this behavior is not described well anywhere and thus it’s not intuitive. Without stumbling upon some github issues or SO answers one cannot simply know what distributes and what doesnt. Also - I completely dont understand why a conditional type makes this work 🤷♂ |
Yeah, it is quite complex to type javascript anyways. This is described in the handbook, but probably not emphasized enough (I agree). The type system is just an API to produce types, with its own syntax, which is very basic & rough. That is why my goal is to provide a smoother user experience. |
I hope that one day type providers will make their way through. This way we will be able to program the types (like in ts-toolbelt) but in ts/js directly (with far better performance). But this is still in discussion/needing proposal, and is not a milestone yet (and could also never happen). |
🎁 Pull Request
tst
folder)npm test
Is there any breaking changes?
Anything else worth mentioning?
A lot more of similar types could be added (for example DistributiveOptional) but I'm not yet sure what do you think about this one.