Skip to content

Misleading error TS2410 #10601

@yortus

Description

@yortus

TypeScript Version: nightly (2.1.0-dev.20160815)

Code

// NB: non-strict code, valid JavaScript
var dyn = { foo: 'bar' };
with (dyn) {/***/} // ERROR TS2410: All symbols within a 'with' block will be resolved to 'any'

Expected behavior:

Error message that says some thing like "with statement is not supported in TypeScript"

Actual behavior:

The error as shown in the code above. What's confusing is that:

  • the error is attributed to the argument of the with statement (not to the statement itself)
  • the 'error' is just a message saying that you'll lose typing within the block, which is a consequence of dynamic scoping, but not an error in itself.
  • there's no mention of an error or a fix, or that with is not supported in TypeScript.

From this message, I got the impression there was some way of arranging the with statement or its argument to get it to compile. But I think there isn't.

If you are porting code to TypeScript and it contains with statements, the only way you'll ever get an error-free build is when you remove all the with statements. To me that means with statements are not supported in TypeScript, period. I think it would be clearer to just state that in the error message (perhaps with the current message as a secondary explanation).

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedA PR has been merged for this issueHelp WantedYou can do thisSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions