Skip to content

Commit

Permalink
[flow] Test showing duplicated errors on indexed object subtyping
Browse files Browse the repository at this point in the history
Summary:
I'd like to make an improvement to these errors so that we only emit the value-side errors if the key check already passes. Showing the bad error behavior with a test in this diff. The additional errors provide very little value.

Changelog: [internal]

Reviewed By: SamChou19815

Differential Revision: D69023898

fbshipit-source-id: f4a5044c12846ae3c14e6d8a26d2343325146d49
  • Loading branch information
jbrown215 authored and facebook-github-bot committed Feb 3, 2025
1 parent f2dcd93 commit 52b04be
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
40 changes: 39 additions & 1 deletion tests/indexed_objects/indexed_objects.exp
Original file line number Diff line number Diff line change
@@ -1 +1,39 @@
Found 0 errors
Error ---------------------------------------------------------------------------------------------------- test.js:15:23

Cannot assign object literal to `error1` because string `foo` [1] is incompatible with string prefixed with `data-` [2]
in the indexer property's key. [incompatible-type]

test.js:15:23
15| const error1: Props = {foo: 3};
^^^^^^^^ [1]

References:
test.js:11:4
11| [StringPrefix<'data-'>]: string | void,
^^^^^^^^^^^^^^^^^^^^^ [2]


Error ---------------------------------------------------------------------------------------------------- test.js:15:29

Cannot assign object literal to `error1` because in property `foo`: [incompatible-type]
- Either number [1] is incompatible with string [2].
- Or number [1] is incompatible with undefined [3].

test.js:15:29
15| const error1: Props = {foo: 3};
^ [1]

References:
test.js:11:28
11| [StringPrefix<'data-'>]: string | void,
^^^^^^ [2]
test.js:11:37
11| [StringPrefix<'data-'>]: string | void,
^^^^ [3]



Found 2 errors

Only showing the most relevant union/intersection branches.
To see all branches, re-run Flow with --show-all-branches
7 changes: 7 additions & 0 deletions tests/indexed_objects/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ const y: Y = {foo: 3}; // No error

type Z = $Exact<{[string]: number}>;
const z: Z = {foo: 3}; // No error

type Props = {
[StringPrefix<'data-'>]: string | void,
}

// TODO: Combine errors
const error1: Props = {foo: 3};

0 comments on commit 52b04be

Please sign in to comment.