-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Current type for Array.prototype.includes
may reject valid use cases
#53904
Comments
Please search for duplicates before logging new issues |
@RyanCavanaugh I cannot find any open issue on this |
@RyanCavanaugh All the dupes of this tend to get closed and duped to #14520; anyone searching for open issues about this is unlikely to find that one organically. |
And I have no idea why this is considered a dup of #14520. That one has nothing to do with this since |
There are five duplicate issues with The missing type system feature to represent this would be #14520. |
I am not requesting a type system feature, I am requesting a change to the signature. |
The proposed signature allows any argument, which we consider to be too loose: a.includes({ foo: 23 }) // should fail, but doesn't In general most feedback we get is that TS should be stricter by default (preferring false positives over false negatives) and people should have to "do something" to get looser behavior. The current |
Ok I guess I need to find a way to "if some type is never then raise a type error" to get this pass. |
Just to note, you can always add in whatever signature you like into a global declaration merge. It'll be selected first if it matches. |
To enforce stricter type checking, you can manually add the suggested fix to a global declaration merge. This will ensure that the custom signature takes precedence and provides the desired type checking behavior. Please note that this fix specifically addresses the behavior of Array.prototype.includes and does not cover broader type system features. For further information on the general representation of type system features, refer to issue #14520. |
To be clear, the thing that you do if you have the global signature merge is make type checking less strict, not more strict |
lib Update Request
Configuration Check
My compilation target is
ESNEXT
and my lib isESNEXT
.Missing / Incorrect Definition
This is
lib.es2016.array
Sample Code
Problem may relevant:
Suggested fix:
And for ReadonlyArray as well.
Documentation Link
Array.prototype.includes
, but irrelevant.https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes
The text was updated successfully, but these errors were encountered: