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

Immediately-executed callback function not considered when refining type. #52471

Closed
bluepnume opened this issue Jan 27, 2023 · 2 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@bluepnume
Copy link

bluepnume commented Jan 27, 2023

Bug Report

let foo = false;

[ 1, 2, 3 ].map(() => {
  foo = true;
});

type Foo = typeof foo;

// Foo resolves to `false`

Ideally Foo should resolve to boolean here

🔎 Search Terms

typescript immedately executed callback refine type

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about immediately-executed callback functions

⏯ Playground Link

Playground link with relevant code

💻 Code

let foo = false;

[ 1, 2, 3 ].map(() => {
  foo = true;
});

type Foo = typeof foo;

// Foo resolves to `false`

🙁 Actual behavior

Foo resolved to false, even though the runtime value is true

🙂 Expected behavior

Foo should resolve to boolean - since TypeScript does not intrinsically know if a callback will be called immediately or asynchronously.

@bluepnume bluepnume changed the title Immediately-executed callback function not considered when evaluating type. Immediately-executed callback function not considered when refining type. Jan 27, 2023
@MartinJohns
Copy link
Contributor

MartinJohns commented Jan 27, 2023

Duplicate of #11498. Relevant: #9998

@DanielRosenwasser DanielRosenwasser added the Duplicate An existing issue was already created label Jan 28, 2023
@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

4 participants