-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Maintain modifiers on Omit
#31205
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
Maintain modifiers on Omit
#31205
Conversation
It was nice to have a better error message with the name BTW, why |
@@ -1446,9 +1446,7 @@ type Extract<T, U> = T extends U ? T : never; | |||
/** | |||
* Construct a type with the properties of T except for those in type K. | |||
*/ | |||
type Omit<T, K extends keyof any> = { |
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.
🤔Why can't this be K extends keyof T
to make the type homomorphic?
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 don't believe that would make the type homomorphic, would it @ahejlsberg?
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.
Yeah, discussed offline, but for reasons outlined below, the fact that it's not just a simple keyof T
or K
(where K extends keyof T
) means that TypeScript can't trivially look at that and say "yup, we gotta keep the modifiers around on this one".
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.
Could also do
type Omit<T, K extends keyof any> = T extends unknown ? Pick<T, Exclude<keyof T, K>> : never;
that is to say: making the builtin Omit
distributive. (Which'd give it an alias symbol, too) A bunch of library authors end up swapping their internal Omit
to this once they get into situations involving unions.
Distributive conditional like this have perf issues when nested repeatedly right now, tho, sooooo.... ehhhhh?
What it comes down to is just the rules for when a mapped type decides it should maintain the modifiers, and right now it never does anything "smart" if the constraint (the thing after the
Yeah. I agree. ☹ |
@DanielRosenwasser is it planned to get this smart "in" in the near future ? |
I'm not sure what you're referring to - the functionality here was implemented. If you have a specific suggestion for new/different functionality in mapped types it's probably best to create a separate issue. |
I'm not sure what you're referring to - the changes here were merged and will be in TypeScript 3.5. If you have a specific suggestion for new/different functionality in mapped types it's probably best to create a separate issue. |
Sorry for the confusion... So you reverted the So my question is: will |
I think it is possible, but that change is not something I can personally dedicate a ton of time towards, and there are other possible changes that are more in-demand at the moment. |
Fixes #31190.