Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Flow data flow analysis loses info under a lambda
/* @flow */
/* Paste this into https://flow.org/try/ to see the bug: */
const f = (lut: ?{[key: string]: number}): number => {
// This correctly notices that we're doing a null check on lut:
const testKey = 'fizz'
const y = (lut != null) ? lut[testKey] : 0
// Putting the access of lut under a lambda (the arg to map)
// loses this info:
const keyList = ['foo','fee','foe']
const zs = (lut != null) ? keyList.map(k => lut[k]) : []
return y
}
@antonycourtney

This comment has been minimized.

Copy link
Owner Author

antonycourtney commented Mar 31, 2017

Actually this may just be Flow being overly conservative --
See:
https://flow.org/en/docs/lang/refinements/

And, indeed, a workaround is to change first two lines to:

const f = (inLut: ?{[key: string]: number}): number => {
  const lut = inLut

and then it all works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.