This code passes the flow check:
/* @flow */ function test (list: ?Array<string>): Promise<number> { if(list !== null && list !== undefined) { return Promise.resolve(list.length) } else { return Promise.resolve(0) } } console.log(test(null)) Whereas the following gets a null check error
/* @flow */ function test (list: ?Array<string>): Promise<number> { if(list !== null && list !== undefined) { return Promise.resolve().then(() => list.length) } else { return Promise.resolve(0) } } console.log(test(null)) error:
property `length`. Property cannot be accessed on possibly null value Clearly list cannot be null so there must be something about the code structure that makes flow unable to recognise this.
I would like to understand what limitation I am hitting and how I can work around it. Thanks!