-
Notifications
You must be signed in to change notification settings - Fork 12.8k
When using Omit, (TypeA | TypeB) & {...} doesn't work as expected anymore #46220
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
Comments
Omit uses |
Hmm, okay, is there any way to accomplish what I expect then? |
Look up "distributive omit". Besides that there simply is no good working solution to enforce the absence of a property in TypeScript. Trying to design your code like this is doomed to cause pain. |
A bit of further explanation, because I'm bored right now: ... And while I wrote this I realized that The type Now This is what I wrote first, which does not fully apply here: The keyof type operator will return all keys of your type, which are You expected Here's an example implementation: https://stackoverflow.com/a/57103940 Hope that makes sense and is somewhat understandable. |
Clear, thank you for the detailed answer ! :) |
Bug Report
🔎 Search Terms
Omit, OR
🕗 Version & Regression Information
I tried multiple versions on the playground, but all(?) of them have it.
If using Omit, an OR statement doesn't work as expected anymore.
(sorry, I don't know how to call the
(TypeA | TypeB)
part)⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
No error for
test1
🙂 Expected behavior
Error like
test2
The text was updated successfully, but these errors were encountered: