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

Incorrect return type from function union #51259

Closed
kesupile opened this issue Oct 21, 2022 · 5 comments
Closed

Incorrect return type from function union #51259

kesupile opened this issue Oct 21, 2022 · 5 comments
Labels
Duplicate An existing issue was already created

Comments

@kesupile
Copy link

Bug Report

🔎 Search Terms

Incorrect union of function return type, function incorrect union

🕗 Version & Regression Information

v4.8.4 - This is the behaviour in every version I tried, and I reviewed the FAQ for entries about functions and unions

⏯ Playground Link

Playground link with relevant code

💻 Code

image

🙁 Actual behavior

output is { w: number; x: string; }

🙂 Expected behavior

output is { w: number; x: string; } | { w: number; x: string; y: boolean; z: symbol}

@fatcerberus
Copy link

This is due to subtype reduction: bar’s return type is a subtype of foo’s, so it’s eliminated from the union. This is by design, e.g. see #49710

@fatcerberus
Copy link

Closest thing to a canonical duplicate is probably #46449

@kesupile
Copy link
Author

Thanks for the quick response. Is there a document I can read that explains the reasoning for the design decision; I'm curious.

@fatcerberus
Copy link

No official documentation I could find, but here’s the original PR that implemented it: #4537

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Oct 21, 2022
@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