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

Array‘s includes and indexOf parameters whether is any more suitable #55090

Closed
1587315093 opened this issue Jul 20, 2023 · 4 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@1587315093
Copy link

Bug Report

🔎 Search Terms

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions ______ and _______
  • 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

Playground link with relevant code

💻 Code

const test1 = [123].includes("456")
const test2 = [true].includes(123)

🙁 Actual behavior

Argument of type 'string' is not assignable to parameter of type 'number'.
image

🙂 Expected behavior

I think includes should accept any type, after all it is a judgment function

image

@MartinJohns
Copy link
Contributor

Duplicate of #14520.

@fatcerberus
Copy link

For the record: proposals to re-type the parameter to any (in lieu of #14520) have been outright rejected in the past on the grounds that it should be an error if, e.g., you check whether string[] contains a number.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jul 20, 2023
@1587315093
Copy link
Author

For the record: proposals to re-type the parameter to any (in lieu of #14520) have been outright rejected in the past on the grounds that it should be an error if, e.g., you check whether string[] contains a number.

But it feels a bit inflexible. When I use [null, undefined]. includes (value) to detect whether an external source's value is null and undefined, a prompt will appear. shouldn't the judgment of includes be more flexible

@RyanCavanaugh
Copy link
Member

You're totally free to add the any overload to your project if that's the behavior you'd prefer.

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