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

Type checking is incorrect in array filtering #58730

Closed
magiskboy opened this issue Jun 1, 2024 · 2 comments
Closed

Type checking is incorrect in array filtering #58730

magiskboy opened this issue Jun 1, 2024 · 2 comments

Comments

@magiskboy
Copy link

magiskboy commented Jun 1, 2024

🔎 Search Terms

  • check type in null filtering in array
  • null-value is still detected by typescript although they was filtered in array

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions ______ and _______
  • This changed in commit or PR _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
  • I was unable to test this on prior versions because _______

⏯ Playground Link

No response

💻 Code

const filteredClaimIds = claimIds.filter((i) => typeof i === "string");
if (filteredClaimIds.length > 0) {
  await this.claimService.updateClaimBySubscriptionId(
    filteredClaimIds,
    {
      status: "cancelled",
    }
  );
}

🙁 Actual behavior

this.claimService.updateClaimBySubscriptionId requires string[] as first parameter and typescript check filteredClaimIds that still contains null value but I filtered in previous line.

image

🙂 Expected behavior

Should be passed without error

Additional information about the issue

Node version: 20.10.0
Typescript version: 5.4.5
Yarn version: 1.22.21

@MartinJohns
Copy link
Contributor

You forgot to fully fill out the issue template.

Duplicate of #38390.

@jcalz
Copy link
Contributor

jcalz commented Jun 1, 2024

Among other things, the template says

Please try the nightly version of TS to see if it's already been fixed. Install typescript@next or use the Playground.

Did you do that? I can't check because your code isn't a reproducible example, but it's quite likely to be already fixed due to TS5.5's upcoming support for inferred type predicates.

Please edit and fill out the issue template properly, and if this is indeed a duplicate of #38390 and fixed in nightly, then do the TS team the favor of closing the issue so they don't have to. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants