Skip to content

False-positive unintentional comparison error with closuresΒ #64314

Description

πŸ”Ž Search Terms

unintentinal, comparison, 2367, overlap

πŸ•— Version & Regression Information

  • typescript: v7.0.2
  • node: v24.14.1
  • pnpm: v12.3.4

⏯ Playground Link

No response

πŸ’» Code

let n: "a" | "b" = "a";

const updateN = () => {
	n = "b";
};

// This comparison appears to be unintentional because the types '"a"' and '"b"' have no overlap. [2367]
if (n === "b") {}

updateN();

// This comparison appears to be unintentional because the types '"a"' and '"b"' have no overlap. [2367]
if (n === "b") {}

n = "b";

// No error
if (n === "b") {}

πŸ™ Actual behavior

If a variable of type "a" | "b" is changed in a function with closure, the LSP fails to catch the change, and assumes that it was never changed.

πŸ™‚ Expected behavior

No error warning, since code works as expected

Additional information about the issue

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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