Skip to content

Commit

Permalink
Update setLinkedRecords flowtype
Browse files Browse the repository at this point in the history
Summary:
Why do this? Because https://fb.workplace.com/groups/243017208059499/posts/250089417352278/?comment_id=254015380293015

* Currently, setLinkedRecords accepts `records: Array<?RecordProxy>`. This means it cannot be called with an `Array<RecordProxy>`, because `setLinkedRecords` would not be prevented from calling `array.push(null)`, violating the type of the array where `setLinkedRecord` is called.
  * This is a somewhat famous problem in Java
* Flow works around this by requiring that array params are invariant, hence an `Array<RecordProxy>` cannot be passed in where an `Array<?RecordProxy>` is accepted.
* However, flow treats `$ReadOnlyArray<T>` differently. It is valid to pass an item with type `$ReadOnlyArray<T>` to a function expecting a `$ReadOnlyArray<?T>`.
* This diff changes `setLinkedRecords` to accept `$ReadOnlyArray<?RecordProxy>` instead of `Array<RecordProxy>`

Differential Revision: D44346850

fbshipit-source-id: ee0eec9512a44430a0036166b7c003bbede7e4f3
  • Loading branch information
Robert Balicki authored and facebook-github-bot committed Mar 24, 2023
1 parent 0cf3af2 commit f9cba52
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/relay-runtime/mutations/RelayRecordProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class RelayRecordProxy implements RecordProxy {
}

setLinkedRecords(
records: Array<?RecordProxy>,
records: $ReadOnlyArray<?RecordProxy>,
name: string,
args?: ?Arguments,
): RecordProxy {
Expand Down
2 changes: 1 addition & 1 deletion packages/relay-runtime/store/RelayStoreTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ export interface RecordProxy {
args?: ?Variables,
): RecordProxy;
setLinkedRecords(
records: Array<?RecordProxy>,
records: $ReadOnlyArray<?RecordProxy>,
name: string,
args?: ?Variables,
): RecordProxy;
Expand Down

0 comments on commit f9cba52

Please sign in to comment.