TypeScript Version: 3.4.1
Search terms: reduce strictFunctionTypes
Code
When the type of passing is explicitly set to boolean, this fails:
const passing: boolean = [1].reduce(pv => true, true);
Expected behavior:
Type inferred from true as the initialValue argument should be boolean.
Actual behavior:
Type 'boolean' is not assignable to type 'true'. <-- error on the return value of the reducer function. It's as if I wrote this:
const passing = [1].reduce(pv => true, true as true);
The workaround I'm using is this:
const passing: boolean = [1].reduce(pv => true, !!true);
This also works:
const passing: boolean = [1].reduce(pv => true, true as boolean);
Playground link:
Turn on strictFunctionTypes to see the error:
https://www.typescriptlang.org/play/#src=const%20passing%3A%20boolean%20%3D%20%5B1%5D.reduce(pv%20%3D%3E%20true%2C%20true)%3B
Related issues: none found
TypeScript Version: 3.4.1
Search terms: reduce strictFunctionTypes
Code
When the type of
passingis explicitly set toboolean, this fails:Expected behavior:
Type inferred from
trueas theinitialValueargument should beboolean.Actual behavior:
Type 'boolean' is not assignable to type 'true'.<-- error on the return value of the reducer function. It's as if I wrote this:The workaround I'm using is this:
This also works:
Playground link:
Turn on strictFunctionTypes to see the error:
https://www.typescriptlang.org/play/#src=const%20passing%3A%20boolean%20%3D%20%5B1%5D.reduce(pv%20%3D%3E%20true%2C%20true)%3B
Related issues: none found