Skip to content

Inconsistent treatment of non-widening string literal types and += #13865

@mariusschulz

Description

@mariusschulz

TypeScript Version: 2.1.5

I'm seeing some inconsistent and confusing behavior regarding non-widening string literal types.
The type checker treats ... += ... differently than ... = ... + ... which looks like a bug to me.

Code:

Example 1:

const empty: "" = "";
let foo = empty;
foo += "bar";          // OK

Example 2:

const empty: "" = "";
let foo = empty;
foo = foo + "bar";     // Error: Type 'string' is not assignable to type '""'.

Expected behavior: Either both examples type-check correctly or none of them do.

Actual behavior: Example 1 type-checks correctly while Example 2 doesn't.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions