Skip to content

Commit

Permalink
[flow] Add test showing spurious spreading error with StringPrefix
Browse files Browse the repository at this point in the history
Summary:
Showing an incompleteness where spreads including a StringPrefix are not taken into account against other properties. We can do better by evaluating the string prefix against the remaining properties.
Changelog: [internal]

Reviewed By: SamChou19815

Differential Revision: D69073157

fbshipit-source-id: 42f1f9df0d5ca27f43c3b75bb2fcfa363bd38b78
  • Loading branch information
jbrown215 authored and facebook-github-bot committed Feb 4, 2025
1 parent 9bf968c commit 2807d4b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
7 changes: 7 additions & 0 deletions tests/string_type_utils/prefix.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,10 @@ type RemainderTypeErr = StringPrefix<'foo', 1>; // ERROR
x as "2"; // OK
x as "3"; // ERROR
}

type SpreadOverOptionalProperies = StringPrefix<'foo'>;
{
const obj: {[SpreadOverOptionalProperies]: number} = {foo: 1};
const objCopy: {[SpreadOverOptionalProperies]: number, bar?: number} = {...obj}; // TODO: NO ERROR

}
20 changes: 19 additions & 1 deletion tests/string_type_utils/string_type_utils.exp
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,24 @@ References:
^^^ [2]


Error ------------------------------------------------------------------------------------------------- prefix.js:120:74

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

prefix.js:120:74
120| const objCopy: {[SpreadOverOptionalProperies]: number, bar?: number} = {...obj}; // TODO: NO ERROR
^^^^^^^^

References:
prefix.js:120:18
120| const objCopy: {[SpreadOverOptionalProperies]: number, bar?: number} = {...obj}; // TODO: NO ERROR
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1]
prefix.js:119:16
119| const obj: {[SpreadOverOptionalProperies]: number} = {foo: 1};
^^^^^^^^^^^^^^^^^^^^^^^^^^^ [2]


Error ---------------------------------------------------------------------------------------------------- suffix.js:6:1

Cannot cast empty string to `Percent` because string [1] is incompatible with string suffixed with `%` [2].
Expand Down Expand Up @@ -683,4 +701,4 @@ References:



Found 46 errors
Found 47 errors

0 comments on commit 2807d4b

Please sign in to comment.