Closed
Description
Bug Report
π Search Terms
Infer, union, return type
π Version & Regression Information
- Tested on 3.8.2 - 4.2.3
β― Playground Link
Playground link with relevant code
π» Code
type TestA = { foo: boolean };
type TestB = { foo: boolean; bar: number }; // diffrence in exta prop
const fn = (val1: TestA, val2: TestB) => {
if (Math.random() > 0.5) {
return val1;
}
return val2;
};
π Actual behavior
fn return type is TestA
π Expected behavior
fn return type is TestA | TestB
This happens when TestB have some similarity with TestA. If I remove foo
from TestB then it works ok.
This is simplified example. What I want is union of all posible types.
Or is there other way how to extract that union type?