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.
$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.
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
$Shapeis only for special use cases, but the inconsistencies when using things like$Shape<T>,$Exact<T>andReactClass<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.