Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shouldn't Array.isArray narrow the type to unknown[]? #43865

Closed
Faithfinder opened this issue Apr 28, 2021 · 4 comments
Closed

Shouldn't Array.isArray narrow the type to unknown[]? #43865

Faithfinder opened this issue Apr 28, 2021 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@Faithfinder
Copy link

lib Update Request

Configuration Check

My compilation target is whatever and my lib is the default.

Missing / Incorrect Definition

Array.isArray()

Sample Code

function parseUnknown(value: unknown): Whatever {
  if (Array.isArray(value) {
    // value is suddenly `any[]` even though I've only confirmed that it's an array
  }
}

I might be missing other usecases, but seems like Array.isArray typing should be smarter than just is any[]

@MartinJohns
Copy link
Contributor

MartinJohns commented Apr 28, 2021

Array.isArray predates unknown and this would be a heavy breaking change.

See #33700.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Apr 28, 2021
@Faithfinder
Copy link
Author

I saw these issues before creating this ticket, yeah. Seems like what's wanted there is some really smart behaviour, but I'm just saying that a simple unknown suits the function better.

If this is so much of a breaking change, introducing it or not is your call, but my proposal doesn't seem like a duplicate to me, just because it's less than other opened issues.

@MartinJohns
Copy link
Contributor

introducing it or not is your call

Not mine, but the TypeScript teams. :-)

but my proposal doesn't seem like a duplicate to me, just because it's less than other opened issues.

What matters in terms of duplicates is the underlying issue, not your proposed solution.

@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants