Skip to content

string & Type intersection produce error in switch statement #10892

@mdaveynis

Description

@mdaveynis

TypeScript Version: 2.0.2

Code

class MyBrand
{
    private _a;
}

function test(strInput: string & MyBrand, numInput: number & MyBrand) {
    switch(strInput)
    {
        case "a": // error: Type '"a"' is not comparable to type 'string & MyBrand'
        return 1;
    }

    switch(numInput)
    {
        case 1: // error: Type '1' is not comparable to type 'number & MyBrand'
        return 1;
    }

    return 0;
}

Expected behavior:
No error reported in case statements.

Actual behavior:
See above error report inline.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions