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

Strange warning with 'instanceof' #18276

Closed
aeschli opened this issue Sep 6, 2017 · 3 comments · Fixed by #19671
Closed

Strange warning with 'instanceof' #18276

aeschli opened this issue Sep 6, 2017 · 3 comments · Fixed by #19671
Assignees
Labels
Fixed A PR has been merged for this issue

Comments

@aeschli
Copy link

aeschli commented Sep 6, 2017

TypeScipt 2.5.2

Sorry, I wasn't able to extract a simplified example:

  • git clone https://github.com/Microsoft/vscode-css-languageservice.git
  • cd vscode-css-languageservice
  • git checkout 73f8707
  • npm install
  • npm run compile

src/services/cssCompletion.ts(804,47) error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter.
link to cssCompletion.ts: 804

image

It's a new error, not reported by a previous version of typescript.
Both nodes.HexColorValue(link) and nodes.Function(link) are classes that extend base class nodes.Node(link). The way I see it, the instanceof test is valid code to test the runtime types of the object.

Adding a brand field _hexColorValue : void; to nodes.HexColorValue fixes the issue, so maybe this is related to #12083.
At the very least the message should be improved, but IMO the error is invalid.

@ezequiel-umu
Copy link

The compiler is telling you that the right part of your || operation is never happening. It may be a bug, but you should add the definitions of nodes.HexColorValue, nodes.Function and nodes.Node to be sure. Also, try to do a simplified version of the code and use text instead of images.

aeschli added a commit to microsoft/vscode-css-languageservice that referenced this issue Sep 6, 2017
@aeschli
Copy link
Author

aeschli commented Sep 6, 2017

@ezequiel-umu Thanks for the reply. As mentioned, I was not able to reproduce the issue with a simplified version. I added links to the source code. But the steps to reproduce are also quite simple, see the description.

@ezequiel-umu
Copy link

I didn't try to reproduce, but to me that looks like the problem you mentioned:

#12083

A bad decision making instanceof a structural check at compile time IMHO.

@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Nov 2, 2017
@mhegazy mhegazy added this to the TypeScript 2.7 milestone Nov 2, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Fixed A PR has been merged for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants