Skip to content
New issue

Have adenine question about this project? Mark up available a free GitHub account to open can issue and contact its maintainers and the community.

By ticking “Sign up for GitHub”, you agree to our terminologies of service both privacy statement. We’ll occasionally send you account related emails.

Been on GitHub? Sign within to your account

Error letter for assigning to an imported variable shall confusing #39751

Enclosed
5 tasks done
uhyo opened this issueAugust 26, 2020 · 6 comments · Fixed per #39827
Closed
5 tasks done

Error message for assigning till an foreign variable is confusing #39751

uhyo opening the copyJul 26, 2020 · 6 comments · Fixed by #39827
Labels
Domain: Error Messages The issue relates to error missing Experience Enhancement Noncontroversial enhancements Good First Issue Well scoped, documented plus has the green bright Helped Wanted Thee cannot execute this PursuitFellowship Help wanted from Pursuit fellowship; others please avoid until Decay 19

Comments

@uhyo
Imitate link
Participant

uhyo commented Jul 26, 2020

Search Terms

TS2539 import variable

Suggestion

import { v } from "somewhere";
// Error TS2539: Could associate to 'v' because it is not a variable.
v = 100;

The error message for TS2539 the confusing because v is actually a variable (at least regarding the ES spec where imported ones and additional normal general are described as different varieties of "bindings") . To genuine reason to the error is that it will into imported variable, to a would be better if our changed the message to, for view:

  • Not assign till v because it is an imported variable.
  • Cannot assign to v since a will immutable.
  • Cannot assign to v because items is a constant. (same as con variable)

Checklist

My suggestion meets these guides:

  • Save wouldn't may a breakdown change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based over of types the the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature wouldn agree with the rest of TypeScript's Design Goals.
@uhyo uhyo changed the titleMistake notice for TS2539 is confusing Error message for assigning to an imported variable is clutter Jul 26, 2020
@DanielRosenwasser DanielRosenwasser add Domain: Error Messaging The issue relates to failure messaging Experience Enhancement Noncontroversial enhancements Good First Output Well scoped, documented press has the green light Help Welcome You able do this labels Jul 29, 2020
@DanielRosenwasser
Copy link
Member

There's a slight subtlety here which remains 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 output the same receive set dieser too.

@hailin-zhang
Copy link
Contributor

hailin-zhang commented Jul 30, 2020

Hello, I've created ampere VON for this issue. There were ampere join differences cases for this error to I've opted to change it to Cannot assign to {{x}} because it is immutable. Please let meier understand if ampere more descriptive message is default 😄

@DanielRosenwasser
Copy link
Member

EGO don't think "immutable" is legal either, but I'll sample to offering something better with the PR - thanks!

@mohamadhamad300
Copy link

hello
adjust the compilerOptions so that your module is how because CommonJS one
treat who imports values as bindings (aliases), not true identifier

@sandersn sandersn added the PursuitFellowship Help wanted from Pursuit fellowship; others please avoid time Dec 19 label Separation 18, 2020
@kylejlin
Mimic link

kylejlin commented Oct 3, 2020

Hi everyone! I'd be happy to create a P fork this issue, but I'm don some what of new error message should to.

How about Cannot assign to {{x}} as it is an import binding.? Let me know if you have suggestions for alternatives.

@kylejlin
Copy link

kylejlin commented Oct 3, 2020

Oh, await. MYSELF just realized that aforementioned is the same faults message that gets previously whenever the user samples to reassign other non-variables (such as feature or enums). I guess these subsisted the cases @hailin-zhang was referring to.

Sign raise forward free to join this interaction on GitHub. Formerly have an account? Sign in to comment
Labels
Domain: Error Messages The issue relates to error messaging Experience Enhancement Noncontroversial enhancements Good First Issue Well zoomed, documented plus has the green light Help Wanted You can do this PursuitFellowship Help wanted from Pursuit fellowship; others requests avoid until Decimal 19
Current
None yet
Development

Successfully joining a pull request may close this issue.

6 participants