flown icon indicating copy to clipboard operation
flown copied to clipboard

Error when Reduce is used more than one-time

Open oonsamyi opened this issue 5 years ago • 0 comments

When a function that uses Reduce type is called more than one-time, flow error occurs:

type MergeAll<T> = Reduce<<X, V>(V) => X => { ...$Exact<X>, ...$Exact<V> }, {}, T>

declare function mergeAll<A>(A): MergeAll<A>

const x = mergeAll([{ a: 1 }, { b: 1 }, { c: 1 }, { a: 2 }])
const xx = mergeAll([{ a: 1 }, { b: 1 }, { c: 1 }, { a: 2 }])

// try to comment this line, the error disappears
;(x: { a: 2, b: 1, c: 1 }) // rightly

// or try to comment this line, the error disappears too
;(xx: { a: 2, b: 1, c: 1 }) // error?!

Link to repl

oonsamyi avatar Jun 30 '19 14:06 oonsamyi