Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mariusschulz opened this issue Feb 3, 2017 · 0 comments · Fixed by #52493
Closed

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

mariusschulz opened this issue Feb 3, 2017 · 0 comments · Fixed by #52493
Labels
Bug A bug in TypeScript
Milestone

Comments

@mariusschulz
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants