Skip to content

Error message at a constant or a read-only property could be more specific #28297

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

Closed
ghost opened this issue Nov 1, 2018 · 3 comments
Closed
Labels
Domain: Error Messages The issue relates to error messaging Experience Enhancement Noncontroversial enhancements

Comments

@ghost
Copy link

ghost commented Nov 1, 2018

TypeScript Version: 3.2.0-dev.20181101

Code

const isMutable = false;
isMutable = true;

Expected behavior:

Cannot assign to 'isMutable' because it is a constant.

Actual behavior:

Cannot assign to 'isMutable' because it is a constant or a read-only property. It's obviously not a property, and the compiler should be able to tell this. Note this is more tricky with namespace N { export const x = 0; }, which is also a property, but I think calling it just "a constant" in that case is fine.

@ghost ghost added Suggestion An idea for TypeScript Domain: Error Messages The issue relates to error messaging labels Nov 1, 2018
@a-tarasyuk
Copy link
Contributor

@Andy-MS What about the following case?

Array = [];

Which error message is correct?

Cannot assign to 'Array' because it is a constant.

or

Cannot assign to 'Array' because it is a constant or a read-only property.

@ghost
Copy link
Author

ghost commented Nov 2, 2018

That's declared as declare const Array: ArrayConstructor; so it should be the former case ("because it is a constant.").

@DanielRosenwasser
Copy link
Member

Thanks @a-tarasyuk!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: Error Messages The issue relates to error messaging Experience Enhancement Noncontroversial enhancements
Projects
None yet
Development

No branches or pull requests

3 participants