Skip to content

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

Merged

Conversation

Zzzen
Copy link
Contributor

@Zzzen Zzzen commented Aug 7, 2021

Fixes #45333

@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Aug 7, 2021
~~~
!!! 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"]'?
Copy link
Member

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.

Copy link
Member

@andrewbranch andrewbranch left a 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 🌟

Copy link
Member

@DanielRosenwasser DanielRosenwasser left a 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));
Copy link
Contributor Author

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!

Copy link
Member

@DanielRosenwasser DanielRosenwasser left a 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Namespace.Interface.prop gives wrong error message
4 participants