Skip to content

FlowLib: Add typed Set wrapper (#1940)#1940

Open
avp wants to merge 17 commits intofacebook:static_hfrom
avp:export-D96520014
Open

FlowLib: Add typed Set wrapper (#1940)#1940
avp wants to merge 17 commits intofacebook:static_hfrom
avp:export-D96520014

Conversation

@avp
Copy link
Copy Markdown
Contributor

@avp avp commented Mar 16, 2026

Summary:

Add a generic Set<T> to FlowLib that wraps the native Set
with typed add/has/delete/clear/forEach methods, allowing
typed code to use Set methods directly.

Reviewed By: micleo2

Differential Revision: D96520014

@meta-cla meta-cla bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Mar 16, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync bot commented Mar 16, 2026

@avp has exported this pull request. If you are a Meta employee, you can view the originating Diff in D96520014.

@meta-codesync meta-codesync bot changed the title FlowLib: Add typed Set wrapper FlowLib: Add typed Set wrapper (#1940) Mar 17, 2026
avp added a commit to avp/hermes that referenced this pull request Mar 17, 2026
Summary:
Pull Request resolved: facebook#1940

Add a generic `Set<T>` to FlowLib that wraps the native Set
with typed add/has/delete/clear/forEach methods, allowing
typed code to use Set methods directly.

Differential Revision: D96520014
@avp avp force-pushed the export-D96520014 branch from 8293c3f to 1b60c92 Compare March 17, 2026 16:57
avp added a commit to avp/hermes that referenced this pull request Mar 17, 2026
Summary:
Pull Request resolved: facebook#1940

Add a generic `Set<T>` to FlowLib that wraps the native Set
with typed add/has/delete/clear/forEach methods, allowing
typed code to use Set methods directly.

Differential Revision: D96520014
@avp avp force-pushed the export-D96520014 branch from 1b60c92 to 1128889 Compare March 17, 2026 21:19
avp added a commit to avp/hermes that referenced this pull request Mar 18, 2026
Summary:
Pull Request resolved: facebook#1940

Add a generic `Set<T>` to FlowLib that wraps the native Set
with typed add/has/delete/clear/forEach methods, allowing
typed code to use Set methods directly.

Differential Revision: D96520014
@avp avp force-pushed the export-D96520014 branch from 1128889 to 67b9fda Compare March 18, 2026 17:53
avp added a commit to avp/hermes that referenced this pull request Mar 23, 2026
Summary:
Pull Request resolved: facebook#1940

Add a generic `Set<T>` to FlowLib that wraps the native Set
with typed add/has/delete/clear/forEach methods, allowing
typed code to use Set methods directly.

Differential Revision: D96520014
@avp avp force-pushed the export-D96520014 branch from 67b9fda to 83f605f Compare March 23, 2026 17:13
avp added a commit to avp/hermes that referenced this pull request Mar 31, 2026
Summary:
Pull Request resolved: facebook#1940

Add a generic `Set<T>` to FlowLib that wraps the native Set
with typed add/has/delete/clear/forEach methods, allowing
typed code to use Set methods directly.

Differential Revision: D96520014
@avp avp force-pushed the export-D96520014 branch from 83f605f to 045e641 Compare March 31, 2026 16:37
avp added a commit to avp/hermes that referenced this pull request Mar 31, 2026
Summary:
Pull Request resolved: facebook#1940

Add a generic `Set<T>` to FlowLib that wraps the native Set
with typed add/has/delete/clear/forEach methods, allowing
typed code to use Set methods directly.

Differential Revision: D96520014
@avp avp force-pushed the export-D96520014 branch from 045e641 to 1644691 Compare March 31, 2026 16:42
avp added a commit to avp/hermes that referenced this pull request Apr 8, 2026
Summary:
Pull Request resolved: facebook#1940

Add a generic `Set<T>` to FlowLib that wraps the native Set
with typed add/has/delete/clear/forEach methods, allowing
typed code to use Set methods directly.

Differential Revision: D96520014
@avp avp force-pushed the export-D96520014 branch from 1644691 to 641d520 Compare April 8, 2026 17:05
avp and others added 11 commits April 17, 2026 09:15
Summary:
We can infer more parameters if we first go over simple formal
parameters (e.g. `t: T`) and just infer those. Then we can infer the
types of callbacks even if their types require going left to right.
We're not doing any arbitrary ordering, just applying a simple
heuristic to significantly improve the power of our rudimentary generic
type inference.

Differential Revision: D100083710
Summary:
We need to allow functions that take fewer parameters to flow into
functions that take more.

```
function foo(cb: number=>void) { cb(1) }
foo( () => {} )
```
is valid Flow and this pattern is quite common in FlowLib.
`cb` need not have only optional parameters.

We also update the type inference matching to allow for non-optional
parameters to get matched (to avoid regressing inference flexibility).

Differential Revision: D100701965
Summary: This can be implemented without compromising inference now.

Differential Revision: D100083709
Summary:
Add indexOf and lastIndexOf methods to the typed Array class in
FlowLib. Both take a single searchElement argument and perform
linear search forward/backward respectively.

Differential Revision: D98024443
Summary:
Add the at() method to the typed Array class in FlowLib. Supports
negative indexing and returns T | void for out-of-bounds access.

Differential Revision: D98024448
Summary:
Add every() and some() predicate methods to the typed Array class
in FlowLib. Both mirror the forEach pattern with boolean callbacks.

Differential Revision: D98024449
Summary:
Add find() and findIndex() methods to the typed Array class in
FlowLib. find() returns T | void, findIndex() returns number (-1
if not found). Both use the standard callback pattern.

Differential Revision: D98024445
Summary:
Add findLast() and findLastIndex() methods to the typed Array class
in FlowLib. These are the reverse-iteration counterparts of find()
and findIndex().

Differential Revision: D98024441
Summary:
Add the join() method to the typed Array class in FlowLib. Takes a
separator string argument and concatenates all elements. Similar to
toString() but with a configurable separator.

Differential Revision: D98024440
Summary:
Add the slice() method to the typed Array class in FlowLib. Takes
start and end indices (both required) with negative index support.
Returns a new array containing the selected elements.

Differential Revision: D98024439
Summary:
Add the toReversed() method to the typed Array class in FlowLib.
Returns a new array with elements in reverse order without modifying
the original.

Differential Revision: D98024452
avp added 6 commits April 17, 2026 09:15
Summary:
Add the with() method to the typed Array class in FlowLib. Returns
a new array with the element at the given index replaced by the
provided value. Supports negative indexing.

Differential Revision: D98024442
Summary:
Add the fill() method to the typed Array class in FlowLib. This is
a mutating method that sets all elements to the given value and
returns the array. Takes only the value argument (no start/end
range since optional params are not supported).

Differential Revision: D98024446
Summary:
Add the reverse() method to the typed Array class in FlowLib. This
is a mutating in-place swap and returns the array.

Differential Revision: D98024447
Summary:
Add the copyWithin() method to the typed Array class in FlowLib.
Handles overlapping copies by copying backward when target > start.
Takes target, start, and end indices (all required) with negative
index support.

Also add TODO comments for pop/shift which cannot be implemented
because assigning this.length is not supported in FlowLib.

Differential Revision: D98024444
Summary:
Add a generic `Map<K, V>` to FlowLib that wraps the native Map
with typed methods, allowing typed code to use
map.get()/map.set() directly instead of using hacks.

Update the widgets benchmark and test to use the new typed Map. Removing
the mapPrototypeGet/mapPrototypeSet hacks and use proper generic types.

Differential Revision: D96520015
Summary:
Pull Request resolved: facebook#1940

Add a generic `Set<T>` to FlowLib that wraps the native Set
with typed add/has/delete/clear/forEach methods, allowing
typed code to use Set methods directly.

Reviewed By: micleo2

Differential Revision: D96520014
@avp avp force-pushed the export-D96520014 branch from 641d520 to 2cde04b Compare April 17, 2026 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Do not delete this pull request or issue due to inactivity. fb-exported meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant