-
Notifications
You must be signed in to change notification settings - Fork 12.9k
improve error message for using property of type as type #45354
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
improve error message for using property of type as type #45354
Conversation
~~~ | ||
!!! error TS2694: Namespace 'Color' has no exported member 'Red'. | ||
~~~~~~~~ | ||
!!! error TS2713: Cannot access 'Red.toString' because 'Red' is a type, but not a namespace. Did you mean to retrieve the type of the property 'toString' in 'Red' with 'Red["toString"]'? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we'd really like to suggest typeof Color.Red.toString
first if that would be valid, then fall back to using indexed access syntax.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, what an improvement 🌟
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great except for minor changes I'd like to see before merging.
error(right, Diagnostics._0_has_no_exported_member_named_1_Did_you_mean_2, namespaceName, declarationName, symbolToString(suggestionForNonexistentModule)); | ||
} | ||
else if (canSuggestTypeof) { | ||
error(name, Diagnostics._0_refers_to_a_value_but_is_being_used_as_a_type_here_Did_you_mean_typeof_0, entityNameToString(fullQualifiedName as QualifiedName)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't tried TypeScript 4.4, so I wrote fullQualifiedName as QualifiedName
. After upgrading vscode, I find it is unnecessary. The CFA is really impressive, kudos to you guys!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What an improvement - thank you!
Fixes #45333