Typing of Array.every
and Array.some
is too strict
#30767
Labels
Duplicate
An existing issue was already created
TypeScript Version: 3.4.1
Search Terms:
Array, typing, some, every
Code
Expected behavior:
Should compile without an error.
Actual behavior:
tsc
complains with 2 errors TS2322: Type 'number' is not assignable to type 'boolean'.Playground Link:
A link to a TypeScript Playground "Share" link which demonstrates this behavior
Related Issues:
none
In the spirit of "any valid JavaScript is also valid TypeScript" the code above should compile without errors.
The errors occur because of the type definitions of the
Array
methodsevery
andsome
: The current decalration inlib.es5.d.ts
states, that the first parametercallbackfn
must return aboolean
. This is (in my opinion) too strict, because the JavaScript spec says:Therefore the correct declaration should state, that
callbackfn
returnsany
:BTW, the
Array
methodfilter
inlib.es5.d.ts
is already declared like this:The text was updated successfully, but these errors were encountered: