Skip to content

Unexpected incompatible type with string literal type #16450

Closed
@vilicvane

Description

@vilicvane

TypeScript Version: nightly (2.4.0-dev.20170612)

Code

interface X {
    type: 'x';
    value: string;
}

interface Y {
    type: 'y';
    value: 'none' | 'done';
}

function foo(bar: X | Y) { }

foo({
    type: 'y',
    value: 'done',
});

Expected behavior:

No error.

Actual behavior:

Argument of type '{ type: "y"; value: string; }' is not assignable to parameter of type 'X | Y'.
  Type '{ type: "y"; value: string; }' is not assignable to type 'Y'.
    Types of property 'value' are incompatible.
      Type 'string' is not assignable to type '"none" | "done"'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions