Improve error message for using value as type #29778
Labels
Domain: Error Messages
The issue relates to error messaging
Experience Enhancement
Noncontroversial enhancements
Fixed
A PR has been merged for this issue
Good First Issue
Well scoped, documented and has the green light
Help Wanted
You can do this
Suggestion
An idea for TypeScript
Milestone
TypeScript Version: 3.4.0-dev.20190206
Search Terms: "cannot find name" type error
Code
If you use a type as a value you get a nice error message:
But if you do the same thing in reverse, you get a really confusing one:
Expected behavior:
Error message should say something more like the type one.
Actual behavior:
Error message suggests there is no 't' in scope at all, which is very confusing especially when you have imported t from some other file and you thought it was a type.
Playground Link:
https://www.typescriptlang.org/play/#src=%0D%0Afunction%20goodError()%20%7B%0D%0A%20%20%20%20type%20t%20%3D%20number%3B%0D%0A%20%20%20%20let%20x%20%3D%20t%3B%20%2F%2F%20good%20error%20message%0D%0A%7D%0D%0A%0D%0Afunction%20badError()%20%7B%0D%0A%20%20%20%20let%20t%20%3D%203%3B%0D%0A%20%20%20%20let%20x%3A%20t%3B%20%2F%2F%20bad%20error%20message%0D%0A%7D
Related Issues:
There are some around this same problem with namespaces I think, like
#26391 or #12075
I think this issue is more broadly complaining about issues in this area:
#27630
But the issue I'm filing here is very specific and concrete, with an easy repro.
This issue discusses some suggested fixes for this issue, but I think first we need to fix the error message.
#28975
The text was updated successfully, but these errors were encountered: