Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nested spread prop variance, issue 7242 #7296

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/typing/flow_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10929,6 +10929,9 @@ and flow_opt_p cx ?trace ~use_op ~report_polarity lreason ureason propref =
| Field (_, lt, Neutral),
Field (_, ut, Neutral) ->
unify_opt cx ?trace ~use_op lt ut
| Field (_, (DefT (_, _) | ExactT (_, _) as lt), Positive),
Field (_, (DefT (_, _) as ut), Neutral) ->
flow_opt cx ?trace (lt, UseT (use_op, ut))
(* directional cases *)
| lp, up ->
let x = match propref with Named (_, x) -> Some x | Computed _ -> None in
Expand Down
8 changes: 8 additions & 0 deletions tests/friendly_errors/prop-variance.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@ declare opaque type T;
((any: {-p: T}): {p: T}); // Error: write-only ~> readable
((any: {-p: T}): {+p: T}); // Error: write-only ~> read-only
((any: {-p: T}): {-p: T}); // Ok

type Ob = {|+foo: {| +bar: string |}|};
declare var update: Ob;
({ foo: { bar: 'valid' }, ...update }: Ob); // Ok

type NestedOb = {|+foo: {| +bar: {| +foo: number |} |}|};
declare var update2: NestedOb;
({ foo: { bar: { foo: 123 } }, ...update2 }: NestedOb); // Ok