Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Wrong union type matching #15907

Copy link
Copy link

Description

@dfilatov
Issue body actions

TypeScript Version: 2.3.2

Code

type Action = { type: 'activate' } | { type: 'disactivate' };

function dispatchAction(action: Action): void {

}

const active = true;

dispatchAction({ type : (active? 'disactivate' : 'activate') });

Expected behavior:
Everything is correct. And if I change last line to:

dispatchAction(active? { type : 'disactivate' } : { type : 'activate' });

then no errors will be produced.

Actual behavior:
Error:
Argument of type '{ type: "activate" | "disactivate"; }' is not assignable to parameter of type 'Action'.
Type '{ type: "activate" | "disactivate"; }' is not assignable to type '{ type: "disactivate"; }'.
Types of property 'type' are incompatible.
Type '"activate" | "disactivate"' is not assignable to type '"disactivate"'.
Type '"activate"' is not assignable to type '"disactivate"'.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.