-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed as not planned
Labels
Not a DefectThis behavior is one of several equally-correct optionsThis behavior is one of several equally-correct options
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.
Metadata
Metadata
Assignees
Labels
Not a DefectThis behavior is one of several equally-correct optionsThis behavior is one of several equally-correct options