Skip to content

unintended never type after a null check #44380

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
boopathi opened this issue Jun 2, 2021 · 3 comments
Closed

unintended never type after a null check #44380

boopathi opened this issue Jun 2, 2021 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@boopathi
Copy link

boopathi commented Jun 2, 2021

Bug Report

Some code flows like functions passed to array methods are not considered as immediately invoked and any assignment to a variable inside the array methods are not captured in the outer scope.

For example,

🔎 Search Terms

array methods, never, null check, assignment, variable assignment

🕗 Version & Regression Information

4.3.2

  • This changed between versions 4.1.3 and 4.3.2

⏯ Playground Link

Playground link with relevant code

💻 Code

let map: Map<string, string> | null = null;

[1].map(() => { map = new Map() });

if (map != null) {
  // map is never
  console.log(map.get("something"));
}

🙁 Actual behavior

In the above code, after the null check, the variable map is expected to be of type Map<string,string>, but the assignment inside the Array.map function isn't captured and is considered as never.

Property 'get' does not exist on type 'never'.(2339)

🙂 Expected behavior

The variable map is of the type Map<string, string>

@whzx5byb
Copy link

whzx5byb commented Jun 2, 2021

Duplicate of #44025

@fatcerberus
Copy link

Root cause is #9998.

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

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

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

5 participants