Skip to content

Assignation of incorrect value doesn't type errorΒ #58681

Closed as not planned
Closed as not planned
@phpcoder2022

Description

@phpcoder2022

πŸ”Ž 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions