facebook / facebook/flow

Refining to an array no longer allows me to edit the array using splice

Open
#7,731 7 comments 0 reactions 0 assignees View on GitHub
enhancement Typing: refinements
Dominant language
Rust
Stars
22.3k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

## Missing/Incorrect APIs
Before (last version I checked is `0.92.1`), it was possible to refine `mixed` to an array using `Array.isArray` and edit the array using `splice`:

```
const arr : mixed = foo()

if (Array.isArray(x)) {
const s = arr.splice(0, 3)
}
```
Before, `arr` was an `Array` and this would work. But since 5639532065954e7f66a968af5e68f76a762a9c14, this will no longer work since `arr` will be a `$ReadOnlyArray`.

I still think my code should be valid though, since there's no writing of values into the array so I'm not changing the type (which is what 5639532065954e7f66a968af5e68f76a762a9c14 was designed to tackle).

Maybe there needs to be an intermediate array type that does not allow writing values but does allow for slicing up the array

If not, what would be a good way to work around this? I'm writing code that works with arrays without caring about the values in the array, but that needs to be able to split up the arrays.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.