Skip to content
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

Omit not working properly #54904

Closed
CyberMew opened this issue Jul 7, 2023 · 6 comments
Closed

Omit not working properly #54904

CyberMew opened this issue Jul 7, 2023 · 6 comments
Labels
Duplicate An existing issue was already created

Comments

@CyberMew
Copy link

CyberMew commented Jul 7, 2023

Bug Report

After using Omit<>, my undefined key errored out.

Example of working (before Omit) and notworking (after Omit) inside:
https://www.typescriptlang.org/play?#code/FASwdgLgpgTgZgQwMZQAQEFUG9ir65JAewFdIAuVAZwhnAHMBuXfBCaAWwAcIrKa6YJsAC+oSLEQpUAIWws8AIxAAbFZRz4tqMAg5R+tBsy0jUAH1RkAJlDjgo1xqgD0L1AHkeIIrpUA6UXFoeGQ0AGF5LWIJCijtPGgADwhDQWFTIIgATy40ABFUAF4MVAAyVEiKmWYcvNQAUWLSivDmKCSuIhgIVDq0ADFmwssG5mAYmmoifQA1BBgAOSIIDw4QdkdKIZLNVk3uXkoAImOAGgVUZTVKGzsHazPXd3Q1VHoiImtUAHcAC1UaDAKysVAYnnWEAAPAA+S4xaBxPYJZKpVCnS4iC5aQikOIYsTAfqoAASzTWGyhAyex1xZAgxxhzEmvSoMyg8xgFM21koZN2lzYnB4fHR50u13UVjAtnsYEcTzcVxgRAA1lAwKg-rA0GQVFAqFRUMQOPoJN9SBB4b5EWjkdpUSdjpjsawkMR6U6WCJxkrifyIZTqei6ZBGYwgA

🔎 Search Terms

Omit

🕗 Version & Regression Information

  • This is the behavior in every version I tried.

⏯ Playground Link

Playground link with relevant code

💻 Code

// playground.

🙁 Actual behavior

Error!

🙂 Expected behavior

Working without error by TypeScript when 'bill' key is defined to be undefined.

@MartinJohns
Copy link
Contributor

This is working as intended. See #54451 and the linked issues.

@CyberMew
Copy link
Author

CyberMew commented Jul 7, 2023

Thanks for the hyperlink. Still feels like a bug to me though. When omitting something we expect the rest to stay the same and only the ones mentioned affected. The behaviour doesn’t match up with the meaning of the word at all. Hope they revamp it officially.

@MartinJohns
Copy link
Contributor

If you look up the definition of Omit you will figure out why it's not working as you expect.

Hope they revamp it officially.

As per the issue and it's linked issues: they will not. Now changing the definition of Omit is a too huge breaking change.

@CyberMew
Copy link
Author

CyberMew commented Jul 7, 2023

I looked up the definition of omit as you suggested:
leave out or exclude (someone or something), either intentionally or forgetfully.

Sounds like it’s not working as per definition. It’s erroring out as per my playground. Please enlighten me (with details if possible) if I am missing something here.

@MartinJohns
Copy link
Contributor

Omit is not a conditional type, so it doesn't distribute over unions. It's using keyof, which for union types only returns the keys common to all types of the union. That's where properties are "lost".

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jul 7, 2023
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants