简体   繁体   中英

Covariant Flow types generated by Relay mutation vs non-covariant in Queries

I am having some issues with some types generated by the compiler, specifically between a query and a mutation result that eventually result in the same type. One is sort of like:

fragment Foo on MyType {
  createdAt
  hidden
  locked
}

query {
  foo(...) {
     id
     ...Foo
  }
}

And that generates covariant properties:

export type Foo = {|
  +createdAt: any,
  +hidden: boolean,
  +locked: boolean
|};

And in another place I have:

mutation doSomething(...) {
  clientMutationId
  foo {
    createdAt
    hidden
    locked
  }
}

Which will generate the types:

export type DoSomething_foo = {
    createdAt: any
    hidden: boolean
    locked: boolean 
}

So when I'd try to match the result foo of the mutation and that query fragment calling commit , I get the error:

object type. Covariant property platform incompatible with invariant use in

Try to force-cast your variable :

const a = { ... } : MyForceCast

Sometimes, Flow is not able to choose the right type when you mix them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM