microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
101.03k stars 12.49k forks source link

Handbook should recommend using a user-defined homomorphic `Omit` #54451

Open RyanCavanaugh opened 1 year ago

RyanCavanaugh commented 1 year ago

Bug Report

Per #53188, we know that it'd be better if Omit were homomorphic. In the Handbook we should steer people toward a better user definition, e.g.

type MappedOmit<T, K extends keyof T> = { [P in keyof T as P extends K ? never : P]: T[P] };
Andarist commented 1 year ago

From the user's perspective, it really feels weird to me that this is pushed into the userland.

I totally understand the argument behind not wanting to make changes to the existing Omit. You are concerned with having 2 Omits in the lib files which is also somewhat understandable. It's hard to come up with a perfect name for this, it also might confuse some people. But isn't including this in the handbook already (a) giving this a name, (b) might confuse some people? Shifting the responsibility for defining this type in the userland feels a little bit like a hygiene theater thing to me. (insert Spiderman meme here)

I also wonder what happened to destructure improvements related to MappedOmit from https://github.com/microsoft/TypeScript/pull/53134 ? This PR has been closed without any concrete conclusion about that part and the related design notes also don't address this explicitly anyhow.

fatcerberus commented 1 year ago

insert Spiderman meme here

There are a few of these. Which one are you referencing?

Andarist commented 1 year ago
Two Spidermans pointing at each other and both saying 'You add it' to the other one
jdalrymple commented 1 year ago

Type-fest has a similar function, which is named "Except" which would avoid confusion with the same name?

cshaa commented 3 months ago

I think something like Except should be added to the standard library and Omit should be marked as deprecated, as it's quite the footgun.