You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The foo variable is expected to be of type boolean because it may change to false within the .forEach(...) block. However, TypeScript incorrectly narrows foo's type to true, assuming it will not change.
π Expected behavior
TypeScript should maintain the boolean type for the foo variable, as it can change to false inside the .forEach(...) block when the map's value is accessed and iterated over.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered:
π Search Terms
"type narrowing", "map of set"
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.6.3#code/MYewdgzgLgBAtgQwA4HkBmBlAplAXDAWWQB5oAnASzAHMAaGbKUqSmgPjZgF4YwsB3QsgAUASgDcAKESpMOAHQQcwgEQBrLAE8V9PoMaqEK0RMmSANjhhoQIbjBYBXLFJnpG86svVbjAfnkbMgBRBGAAC2Exbk4Ab0kYa1t7NARzJSkAX1NJUEgQS3lzEGphGxBTIA
π» Code
π Actual behavior
The
foo
variable is expected to be of typeboolean
because it may change tofalse
within the.forEach(...)
block. However, TypeScript incorrectly narrowsfoo
's type totrue
, assuming it will not change.π Expected behavior
TypeScript should maintain the
boolean
type for thefoo
variable, as it can change tofalse
inside the.forEach(...)
block when the map's value is accessed and iterated over.Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: