-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Loosen strictness of Array.prototype.includes()
and Set.prototype.has()
#60559
Comments
Array.prototype.includes()
Array.prototype.includes()
and Set.prototype.has()
Duplicate of #60073 and many many more. Your search terms seem excessive, no wonder you didn't find any of them. I suggest limiting your search terms to a few related word, often with the IMO a type assertion is an appropriate workaround if this is intentional code. |
sorry. Thank you for your time. I didn't see that improving this was already discussed and/or rejected. |
reopen because it's not a duplicate of #60073. This ticket is not about making |
I aggree that this is a duplicate to #26255. A 6 year old, with 27 upvotes closed duplicate. But a duplicate non the less. Then I guess i have to write: + const inArray = (haystack: readonly any[], needle: string): boolean => haystack.includes(needle);
+ inArray(values, value)
- values.includes(value) I hope nobody follows the recommendation on https://www.typescriptlang.org/tsconfig/#suppressImplicitAnyIndexErrors to use
Yes, Sadly I can't show it in the playground, because Fell free to close this issue. |
Again, you can just use a type assertion, IMO the cleanest approach: |
Indeed that works. Not sure why. I internalized that whenever I had to restort to typecasting, that my underlying types or generics are incorrect. Thank you. |
🔍 Search Terms
Example:
This error seems counter intuitive as the entire point of
includes
is to check ifvalue
infoo.includes(value)
is one offoo
.A
Set
andmySet.has(...)
has the same issue.playground
✅ Viability Checklist
⭐ Suggestion
I'd expect typescript to not show an error here.
💻 Use Cases
Now having to deal with the removal
suppressImplicitAnyIndexErrors: true
in typescript 5.6The text was updated successfully, but these errors were encountered: