Skip to content

Assignation of incorrect value doesn't type error #58681

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
phpcoder2022 opened this issue May 28, 2024 · 2 comments
Closed

Assignation of incorrect value doesn't type error #58681

phpcoder2022 opened this issue May 28, 2024 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@phpcoder2022
Copy link

πŸ”Ž Search Terms

incorrect type, incorrect value

πŸ•— Version & Regression Information

TypeScript version: 5.4.5

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/MYewdgzgLgBAwiArmKBTATgZQJ4FsBGIANjALww4HEAUA5AsmlnoUbQJQDcAUFNgA6p4SFBjIwADDAA+MMIgJiAZDADeMANoNRzKkQC6ALhhR0iIQF8e3APQ2YAFQAWASwgxcAQ3meSniBAYUC7gMG4woOjoqMBQAHQUqJBCIABmJq7ufIJh7i64-CABLvguRC58MGkebsARTt4A5qgQcdygkLAuKACSYHXk1KCMGMbaTOxjIkxkAHwwQ9NiANQwAIzsMP7CI+jWRKiwwzpTu+IS1scz5ADMPFdi5A-oMAC06xIXMHYeiNAw+CEGHQIBe+EQsDAIAANBk-mEoLQsk4hAdPABrMJgEwCFwAL08wXA7SWL1e5DWn0433suD+sEBMGBoIBELkMLheURyNRqAxWJx-HxhJCYG47SI-ncAEE1NwYDB+CC0LFUAATCKk046c7WBX8RD4cp1brAaiTGAANxALg1qnlCoybjiz3ErvelIuDoVUEyLtJbwpVJpv3+jOZYLZUNhvvhFSRGV5-O6guFRLFCos3AsQA

πŸ’» Code

const CounterSymbol = Symbol('CounterSymbol');
type Counter = 0 | number & { [CounterSymbol]: true };

// This manual assertion is correct. Sense of this type is impossibility of misc changes.
const intInc = (counter: Counter): Counter => (counter + 1) as Counter;

let counter: Counter = 0;

counter = 3;
counter = counter - 100; // must be error but no, thus it's the leak in typization
counter -= 100; // must be error but no, thus it's the leak in typization

class A {
  protected counter: Counter = 0;

  public inc(): void {
    this.counter = counter - 100;
    this.counter -= 100; // must be error but no, thus it's the leak in typization
  }
}

πŸ™ Actual behavior

Assignation was allow

πŸ™‚ Expected behavior

Assignation was deny

Additional information about the issue

No response

@jcalz
Copy link
Contributor

jcalz commented May 28, 2024

Duplicate of #47027

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jun 6, 2024
@typescript-bot
Copy link
Collaborator

This issue has been marked as "Duplicate" 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 Jun 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants