-
Notifications
You must be signed in to change notification settings - Fork 12.2k
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
Wrong definition of Array.find<T>() in lib.es2015.core.d.ts #38959
Comments
Opened PR #38962 |
This is correct as it is. The point is to provide a type predicate (so a type guard function), to ensure that the found value matches the type. By changing it to Given your example you could fix your code by changing the anonymous arrow function returning a
|
Understood. Makes sense. Thank you. |
TypeScript Version: 3.9.2
Search Terms: Array.find
Expected behavior:
See playground link and code below.
Array.find
has an overload that takes a type parameter. I believe that supplying the type parameter should result in the value returned by.find<T>()
to be typed asT
.Actual behavior:
Compilation error:
find
is defined like this in lib.es2015.core.d.ts:It seems that
=> value is S
should be=> unknown
just like in the second overload.The overload was added in #20385 (see https://github.com/microsoft/TypeScript/pull/20385/files#diff-aaa6939ec3d22a3cca5645eaac94d0beR33)
Related Issues:
Code
Output
Compiler Options
Playground Link: Provided
The text was updated successfully, but these errors were encountered: