TypeScript Version: 3.6
Search Terms: array reduce destructuring binding tuple
Code
const [oops] = [1, 2, 3].reduce((accu, el) => accu.concat(el), []);
Expected behavior: Should be OK (oops gets value 1 at runtime)
Actual behavior: It's not good. The empty array in the second reduce argument gets inferred as an empty tuple and things go downhill quickly.
- On the call
accu.concat(el), we get the error "Type number is not assignable to ConcatArray<never>"
- The
oops identifier gets errored with "Initializer provides no value for this binding element" because we think the return tuple is empty.
Playground Link: Linky
Related Issues: ?