Skip to content

Could handling of Array pop() and shift() be made better? #9249

Closed as not planned
@Dagur

Description

@Dagur

Proposal

In 0.239.x a change was made

Calling shift() and pop() on an Array will now return T | undefined. #8341

Which is great but I was wondering if it could be made a little bit smarter because it leads to checks and $FlowFixMe's that shouldn't be needed.

Use case

Example:

const a = someString.split(",").pop()
Here we know for certain that a is a string because split() will return a non-empty array of strings.

Example 2:

while (stringArray.length > 0) {
  const a = stringArray.shift();
 ...
}

We have made sure that the array is not empty but Flow still insists that a could be undefined.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions