Closed as not planned
Description
π Search Terms
Couldn't think of any :(
π Version & Regression Information
- This is the behavior in every version I tried
β― Playground Link
π» Code
type T = { foo: string, data: { x: number } } | { foo: 'bar', data: {} } | { foo: 'baz', data: {} };
function f1(p: 'bar' | 'baz') {
ok({ foo: p, data: {}})
}
function ok(t: T) {
}
π Actual behavior
I get an error message
Argument of type '{ foo: "bar" | "baz"; data: {}; }' is not assignable to parameter of type 'T'.
Types of property 'data' are incompatible.
Property 'x' is missing in type '{}' but required in type '{ x: number; }'
π Expected behavior
No errors
Additional information about the issue
If I change the parameter to p: 'bar'
, it works. If I change it to p: 'baz'
, it works. If I remove the { foo: string; ... }
option from the union type, it works. But something confuses TS with this specific combination.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment