Skip to content

Updated error message for TS2539 #39827

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
merged 4 commits into from
Mar 11, 2021
Merged

Conversation

hailin-zhang
Copy link
Contributor

Fixes #39751

There were a number of different cases using this error code outside of the one reported so I used a more generic error message. Please let me know if a more descriptive message should be used 👍

Thanks!

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Jul 30, 2020
@ghost
Copy link

ghost commented Jul 30, 2020

CLA assistant check
All CLA requirements met.

@DanielRosenwasser
Copy link
Member

Maybe "because it is not a writable binding" or something - immutable really does imply the entire structure is frozen. Maybe @sandersn has a suggestion.

@orta
Copy link
Contributor

orta commented Jul 30, 2020

because it is not a writable binding

is real jargon-y, perhaps we could narrow down the error handling and explicitly check that it's an import, then offer something like:

Cannot assign to '{0}' because it is imported value which cannot be changed?

@sandersn
Copy link
Member

sandersn commented Jul 30, 2020

I agree, the baselines show that the error happens on, at least, enum, class, function, namespace, import.

If the error distinguishes those cases, you could probably get away with a very simple error, something like:

Cannot assign to '{0}' because it is an import.

It might even be parametrisable:

Cannot assign to '{0}' because it is a(n) {1}.

Edit: But that assumes you can retrieve the keyword fairly easily. Probably 5 different messages is still the right way to go so that it's easier to localise.

@sandersn sandersn self-assigned this Sep 3, 2020
@DanielRosenwasser
Copy link
Member

'{0}' declarations like '{1}' cannot be assigned to.

@vuvuzella
Copy link

vuvuzella commented Oct 10, 2020

'{0}' declarations like '{1}' cannot be assigned to.

I agree with the word declaration. Another variation can be
Cannot assign to '{0}': Previous '{1}' declaration of the same name exists

@sandersn
Copy link
Member

@hailin-zhang do you want to keep working on this?

@hailin-zhang
Copy link
Contributor Author

hailin-zhang commented Oct 28, 2020

@sandersn sorry for the lack of an update, I am OK if somebody wants to take this ticket, if not then I can circle back once I have more time

@sandersn
Copy link
Member

sandersn commented Mar 11, 2021

I switched to multiple errors, and, since undefined was the only one I didn't cover, switched back to the original message for that, since the original covers undefined nicely.

@sandersn sandersn merged commit e44d39d into microsoft:master Mar 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Error message for assigning to an imported variable is confusing
6 participants