Flow: Can't extract argument type using $Call

Created on 4 Sep 2018  路  2Comments  路  Source: facebook/flow

Hi,

Would like to share this result related to $Call. Not sure if this is a bug or expected behavior:

/* @flow */

type Fn = boolean => number

type ReturnType = $Call<<T, R>(T => R) => R, Fn>
type ArgumentType = $Call<<T, R>(T => R) => T, Fn>

// (true: ReturnType); // fails - correct
(1: ArgumentType); // does not fail - wrong?

type ArgumentType2 = $Call<<T, R>(T => R) => T & $NonMaybeType<T>, Fn>
// (1: ArgumentType2); // fails - correct

Try online

Seems ArgumentType has empty type, but ArgumentType2 has the correct boolean one.

The key point is T & $NonMaybeType<T> in the type ArgumentType2. I don't understand why this last bit fixes the type issue, would really appreciate some further explanation if someone knows more about this topic.

Thanks a lot for the library.

Most helpful comment

This appears to be a duplicate of #6647 and #6696.

All 2 comments

This appears to be a duplicate of #6647 and #6696.

Closing as duplicate of #6647

Was this page helpful?
0 / 5 - 0 ratings

Related issues

marcelbeumer picture marcelbeumer  路  3Comments

bennoleslie picture bennoleslie  路  3Comments

Beingbook picture Beingbook  路  3Comments

l2silver picture l2silver  路  3Comments

funtaps picture funtaps  路  3Comments