Local variable refinements are unsafe in TS and Flow. Both are bad, TS is the worst. Seems obvious in hindsight but neither handle local refinement invalidation correctly. I'm not speaking abstractly, this has caused bugs in my code before.
-
Show this thread
-
Flow at least invalidates refinements when calling local functions that mutate variables, but does not follow any indirection https://flow.org/try/#0PQKgBAAgZgNg9gdzAZwC4CcCWBjVYTABQhMApngG4CGMAXGAHYCuAtgEanpgA+KGmDAOZgAvGADk4gNzEoTBrkxwGYKsmSZBDAJIMAJpnSlFygBQBKMAG9CYVes0MAcqw7oLMgL6z5JlWo0tF3ZOC2tbMGoYUTAAJi8fBVQlFRYqATCbO0woMFNUAE8AB1I4XKjRETFxZhD0cUssuzBUAAt0REZSJABRdA73cSc4RldOZFUYeARSPQaZO28I4GAwbVy2zAmENTAAAwDHYLc9ltbSFQAxabAEOCYYPTBsOH7jVBgCsAEozD0qVCkM5AoxQASkFgXVARQ5aXQGIx+DzEOwrMAAFVaWxQrXujzAUHSMAANN9UOIJlRRnUIqYovQ0FghOYvEA …
1 reply 0 retweets 18 likesShow this thread -
TS won't ever invalidate local refinements in this case, even when it can easily statically tell that a function call will https://www.typescriptlang.org/play/#code/DYUwLgBAbghsBcEB2BXAtgIxAJwgHwgGcxsBLJAcwgF4IByOgbgChmAzFJAYzFIHskEGIUKkKSAHLos2ABQBKCAG9mEaHBoQATCwC+rDt14CIaGOQXLVEUmwiywATwAOIPndjAa1WnVSYcOkUVNTUwAAtsPgB3ZBBYgFFsKLk6CT5kaRxCIWBgGJAAEyCWNX1rAHoKiAARATpIJBAioSRHGyRC0mwQHn5BcJwQa2FRcSkAuXkWSuqAFXDSHMJwvhRgQog2c2AAGhswOhyYTMnrLgFiIhJEYjJKTU89IA …
7 replies 1 retweet 22 likesShow this thread -
Replying to @sebmck
Where are you seeing flow break down with invalidation? Pretty sure it handles that TS example fine.
1 reply 0 retweets 1 like
It does handle the TS case. My Flow tweet above has an example that does not fail when indirection is involved though.
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
he/him 