Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Flow data flow analysis loses info under a lambda
/* @flow */
/* Paste this into 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) ? => lut[k]) : []
return y

This comment has been minimized.

Copy link
Owner Author

antonycourtney commented Mar 31, 2017

Actually this may just be Flow being overly conservative --

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.