We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
TypeScript Version: 3.9.7 Search Terms:
type narrowing not working inside array forEach callback
Code
type Observer = {next:()=>void} let observer: Observer|undefined const value = {} if (observer) { Object.keys(value).forEach((name) => { observer.next(); }); }
Expected behavior: No error, narrows type
Actual behavior: Error, doesn't narrow type
Playground Link: https://www.typescriptlang.org/play?#code/C4TwDgpgBA8gRgZwgJwG4qgXigbwHYQAewAXABQCUmAfKgPYCWAJgL4BQbANhMFHYinTISsAWhQAfAK54mEAGYMCTDgGM6eBL1QBDTlOjYc7Ng3lQy-JOOQVcbKKIBWEVcAB0AawggEZXfoQFO7ydMgAojqqABZkZHg6ALZBWNT2jo5WgijuBMSUANwOUCwURSxAA
Related Issues: #36436 #9998
Work arounds
observer
if (observer) { Object.keys(value).forEach((name) => { if (observer) { observer.next(); } }); }
The text was updated successfully, but these errors were encountered:
Duplicate of #9998.
Sorry, something went wrong.
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.
Successfully merging a pull request may close this issue.
TypeScript Version: 3.9.7
Search Terms:
type narrowing not working inside array forEach callback
Code
Expected behavior: No error, narrows type
Actual behavior: Error, doesn't narrow type
Playground Link: https://www.typescriptlang.org/play?#code/C4TwDgpgBA8gRgZwgJwG4qgXigbwHYQAewAXABQCUmAfKgPYCWAJgL4BQbANhMFHYinTISsAWhQAfAK54mEAGYMCTDgGM6eBL1QBDTlOjYc7Ng3lQy-JOOQVcbKKIBWEVcAB0AawggEZXfoQFO7ydMgAojqqABZkZHg6ALZBWNT2jo5WgijuBMSUANwOUCwURSxAA
Related Issues:
#36436
#9998
Work arounds
observer
is defined multiple times (downside is TS imposing on code readability)The text was updated successfully, but these errors were encountered: