Skip to content

Unexpected type failureΒ #57775

@erik-kallen

Description

@erik-kallen

πŸ”Ž Search Terms

Couldn't think of any :(

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

https://www.typescriptlang.org/play?#code/C4TwDgpgBAKlC8UDeUBmB7dAuKBnYATgJYB2A5gDRQAmAhsLTigB44kCuAtgEYQFQBfQVAA+yNJhwBybrQJSqdBkyFCxKDNigzaALwU16jZKoDcAKHOp2JAMbAi6EmgCMACjDTZ80dtn6ASmRzKFCodABrNw1JKDBFIxUBAPMBS2s7BydwqOAcGCCkVPMgA

πŸ’» 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

No one assigned

    Labels

    Not a DefectThis behavior is one of several equally-correct options

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions