Flow: $Shape does not preserve covariance

Created on 12 Apr 2017  路  3Comments  路  Source: facebook/flow

e.g.

/* @flow */

type State= {+foo: number};
function setState(state: $Shape<State>) {
}
setState(({foo: 10}: State));

produces the error:

4: function setState(state: $Shape<State>) {
                                   ^ object type. Covariant property `foo` incompatible with contravariant use in
4: function setState(state: $Shape<State>) {
                                   ^ State

Even though all usage of the foo property is covariant.

DX property variance feature request

Most helpful comment

Yes, but it's used internally by React, so this prevents you marking parts of your state as co-variant. I get that $Shape is only for special use cases, but the inconsistencies when using things like $Shape<T>, $Exact<T> and ReactClass<T> are causing a lot of pain for me. It's death from a thousand cuts. I get that they each seem low-priority, but collectively they have a big impact on the developer experience.

All 3 comments

$Shape is an experimental feature for very specific use-cases.

Yes, but it's used internally by React, so this prevents you marking parts of your state as co-variant. I get that $Shape is only for special use cases, but the inconsistencies when using things like $Shape<T>, $Exact<T> and ReactClass<T> are causing a lot of pain for me. It's death from a thousand cuts. I get that they each seem low-priority, but collectively they have a big impact on the developer experience.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

glenjamin picture glenjamin  路  3Comments

bennoleslie picture bennoleslie  路  3Comments

jamiebuilds picture jamiebuilds  路  3Comments

cubika picture cubika  路  3Comments

doberkofler picture doberkofler  路  3Comments