You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a function has multiple return values, and one of the possible return values is
a union of objects, the return type is inferred as the common properties between that
object, instead of the full union
π Expected behavior
I would expect the object to be the full union, e.g. I would expect the inferred return value of fn to be the same as the explicitly typed value of fnExplicit
The text was updated successfully, but these errors were encountered:
Your type X is already equivalent to {a: number} because any value of type {a: number, b: string} is assignable to {a: number}. If you use a discriminated union for X instead, the issue disappears:
Uh oh!
There was an error while loading. Please reload this page.
Bug Report
π Search Terms
Return Inference Object Unions Multiple Return Types
π Version & Regression Information
Seeing it from version 3+
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
When a function has multiple return values, and one of the possible return values is
a union of objects, the return type is inferred as the common properties between that
object, instead of the full union
π Expected behavior
I would expect the object to be the full union, e.g. I would expect the inferred return value of
fn
to be the same as the explicitly typed value offnExplicit
The text was updated successfully, but these errors were encountered: