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 DistributedOmit type #820
Add DistributedOmit type #820
Conversation
4b354e3
to
b3f1ea1
Compare
b3f1ea1
to
d8a4dd0
Compare
846890d
to
667d549
Compare
source/distributed-omit.d.ts
Outdated
/** | ||
Omits keys from a type, distributing the operation over a union. | ||
|
||
TypeScript's `Omit` doesn't distribute over unions, which causes the following situation: |
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.
It would be useful to have a description in text, not just examples. Examples take longer to understand.
Here's a suggested text. Can you check that it's correct?
TypeScript's `Omit` doesn't distribute over unions, which causes the following situation: | |
TypeScript's `Omit` doesn't distribute over unions, leading to the erasure of unique properties from union members when omitting keys. This creates a type that only retains properties common to all union members, making it impossible to access member-specific properties after the Omit. Essentially, using `Omit` on a union type merges the types into a less specific one, hindering type narrowing and property access based on discriminants. This type solves that. |
Feel free to edit it as you see fit.
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.
Agreed
This doesn't fix that issue as it's missing |
9898ced
to
bdd4be2
Compare
(Sorry for the delay)
Implements
DistributedOmit
, that omits keys from a type, distributing the operation over a union, while also offering autocompletion for keys that can be omitted.Related to #132.
Typescript's
Omit
doesn't distribute over unions, which causes the following situation:While
Except
solves this problem, it restricts the keys you can omit to the ones that are present in ALL union members, whereDistributedOmit
allows you to omit keys that are present in ANY union member.