Skip to content

Number literal type allows increment #14745

Closed
@mihailik

Description

@mihailik

TypeScript Version: 2.2.1 / Playground

Code

var s10: 10 = 10;
s10++;
s10 += 1;
s10 = s10 + 1; // Type 'number' is not assignable to type '10'.

Expected behavior:
Compiler errors on all three lines

Actual behavior:
Only errors on the last line.

This looks like a clear bug. A bit more subtle case is a union of literals where increment may or may not lead to the correct type. That subtlety should probably be folded into integer types, and ignored for now. Increments and += on literal type should error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Won't FixThe severity and priority of this issue do not warrant the time or complexity needed to fix it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions