Relay: Bug: incorrect Flow types for plural fragments

Created on 10 Oct 2018  路  6Comments  路  Source: facebook/relay

Hello! I think I found an error in generated Flow types. Fragments like this:

fragment Ticket_passengers on Passenger @relay(plural: true) {
  id
  ...MyFragment
}

currently generate this Flow type:

export type Ticket_passengers = $ReadOnlyArray<{|
  +id: string,
  +$fragmentRefs: MyFragment$ref
  +$refType: Ticket_passengers$ref,
|}>;

However, most of our types are nullable. This is not problem for most of the cases because we can just import the type and prefix it with ?. But we cannot do it here because it should be:

export type Ticket_passengers = $ReadOnlyArray<?{|
  //                                           ^^

  +id: string,
  +$fragmentRefs: MyFragment$ref
  +$refType: Ticket_passengers$ref,
|}>;

I am afraid it is not possible to do it from outside when imported. It's unfortunate because parrent component defines this type:

+passengers: ?$ReadOnlyArray<?{|
  +$fragmentRefs: Ticket_passengers$ref
|}>

and as you can see these types are incompatible (inner object is correctly nullable here).

Most helpful comment

Is there any plans to support flow typings when using @relay(plural: true) ?

All 6 comments

I think you're right, containers don't filter nulls when vending plural fragment props so the type should be a readonly array of nullable items.

@josephsavona Could you please point me to the right place where this should be fixed? Or explain a little bit more technically what is the problem in Relay so I can focus on the right Relay parts? I got two reports related to this in the last 2 days so I would like to take it more seriously but I am not super familiar with Relay code yet... :)

Is there any plans to support flow typings when using @relay(plural: true) ?

We're happy to accept a PR, RelayFlowGenerator is the place to look.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

I am afraid this is still valid and should not be closed.

Was this page helpful?
0 / 5 - 0 ratings