Skip to content
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

Incorrect Error Message: "Cannot assign to 'name' because it is a constant" Instead of "Identifier 'name' is not defined" for Undefined Identifier Assignment #59317

Closed
Roise-yue opened this issue Jul 17, 2024 · 3 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@Roise-yue
Copy link

πŸ”Ž Search Terms

TS2304 TS2588 constant

πŸ•— Version & Regression Information

  • This changed between versions 5.4.5 and 5.5.3_____

⏯ Playground Link

No response

πŸ’» Code

// function A():void{
//     let yso: string = "bob";
//     name = "smith";
// }

let yso: string = "bob";
name = "smith";

πŸ™ Actual behavior

error massage:

TS2588
Cannot assign to 'name' because it is a constant.
'name' is deprecated.

πŸ™‚ Expected behavior

error massage:

can not find 'name'  / 'name' is not defined

Additional information about the issue

tsconfig.json

{
  "compilerOptions": {
    "target": "ESNext",
    "module": "CommonJS",
    "moduleResolution": "Node",
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "lib": ["es2023","dom"]
  },
  "include": [
    "TScorpus/*"
  ],
  "exclude": [
    "node_modules"
  ]
}
@MartinJohns
Copy link
Contributor

  • This changed between versions 5.4.5 and 5.5.3_____

I don't see any difference in behaviour between these versions.

This is, unfortunately, working as intended. In the browser context you have a global name variable. See also #18433.

@Roise-yue
Copy link
Author

Thank you for your response to this question. I didn't quite understand why name is a constant before, but now I have a better understanding of this issue.

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Jul 17, 2024
@typescript-bot
Copy link
Collaborator

This issue has been marked as "Working as Intended" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

4 participants