Skip to content
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

Not possible to compile latest Angular 2 due to literal types #11794

Closed
alfaproject opened this issue Oct 22, 2016 · 2 comments
Closed

Not possible to compile latest Angular 2 due to literal types #11794

alfaproject opened this issue Oct 22, 2016 · 2 comments

Comments

@alfaproject
Copy link

TypeScript Version: nightly (2.1.0-dev.20161022)

Code
https://github.com/angular/angular/blob/master/modules/%40angular/compiler/src/expression_parser/lexer.ts#L296

Expected behavior:
No compiler errors.

Actual behavior:

› ./node_modules/.bin/tsc --version
Version 2.1.0-dev.20161022

› ./node_modules/.bin/tsc -p ./modules/tsconfig.json
modules/@angular/compiler/src/expression_parser/lexer.ts(296,13): error TS2365: Operator '==' cannot be applied to types '92' and '117'.

It looks like literal type inference went a bit aggressive with this particular piece of code.
Funnily enough, I've tried to isolate the issue in a more concise class with just a scan method but works all the time, so it must be some weird combination of things going on here, which I couldn't figure out. ):

@alfaproject alfaproject changed the title Not possible to compile latest Angular 2 modules due to literal types Not possible to compile latest Angular 2 due to literal types Oct 22, 2016
@alfaproject
Copy link
Author

alfaproject commented Oct 22, 2016

Forgot to say that it is possible to prevent that error by widening the literal type to number, like this:

if (this.peek == <number>chars.$u) {
  // ...
}

But still looks like some weird bug to me.

@ahejlsberg
Copy link
Member

This is an effect of #11587. In the if (this.peek == chars.$BACKSLASH) test we narrow this.peek to the literal type 92 (the value of chars.$BACKSLASH). We then complain when you try to compare this literal type to the literal type 117 (the value of chars.$u). The issue of course is that we don't know that this.advance() has a side effect on the value of this.peek.

Interestingly, we had a very similar issue with TypeScript's own parser as described here. We opted to use an accessor function to obtain the value of the side effected variable.

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label May 24, 2017
@RyanCavanaugh RyanCavanaugh removed the Needs Investigation This issue needs a team member to investigate its status. label Sep 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants