Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Error message for assigning to an imported variable is confusing #39751
Comments
|
There's a slight subtlety here which is that there's another syntax called "namespace import aliases". namespace foo { export var x = 100; }
import X = foo;
X = { x: 100 };
// ~
// Cannot assign to 'X' because it is not a variable.Maybe it's fine to issue the same message on these too. |
|
Hello, I've created a PR for this issue. There were a couple different cases for this error so I've opted to change it to |
|
I don't think "immutable" is right either, but I'll try to provide something better in the PR - thanks! |
|
hello |
|
Hi everyone! I'd be happy to create a PR for this issue, but I'm not certain what the new error message should be. How about |
|
Oh, wait. I just realized that this is the same error message that gets used when the user tries to reassign other non-variables (such as functions or enums). I guess these were the cases @hailin-zhang was referring to. |


Search Terms
TS2539 import variable
Suggestion
The error message for TS2539 is confusing because
vis actually a variable (at least regarding the ES spec where imported ones and other normal variables are described as different kinds of "bindings") . The true reason of the error is that it is an imported variable, so it would be better if we changed the message to, for example:vbecause it is an imported variable.vbecause it is immutable.vbecause it is a constant. (same asconstvariable)Checklist
My suggestion meets these guidelines: