-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed
Description
Bug Report
The compiler cannot find an intersection between the reduce function for number[]
and Uint8Array
.
From the error message, it looks like the compiler is raising an issue because of the fourth parameter having different types, but since I don't use the fourth parameter, it hardly seems relevant in this specific case.
🔎 Search Terms
- Uint8Array
🕗 Version & Regression Information
I see this issue in v3.3.3333, v4.3.2 (current stable) and v4.4.0-dev.20210615 (current nightly).
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about https://github.com/Microsoft/TypeScript/wiki/FAQ#why-are-functions-with-fewer-parameters-assignable-to-functions-that-take-more-parameters
- It indicates that the compiler should work as I expected, not as it actually works.
- I was unable to test this on versions prior to v3.3.3333 because the playground did not support older versions.
⏯ Playground Link
Playground link with relevant code
💻 Code
// This function fails
function combined(x: Uint8Array | Array<number>): number {
return x.reduce((s: number, x: number) => s + x * x, 0)
}
// This function has no issues
function uiint8array(x: Uint8Array): number {
return x.reduce((s: number, x: number) => s + x * x, 0)
}
// This function has no issues
function numberarray(x: Array<number>): number {
return x.reduce((s: number, x: number) => s + x * x, 0)
}
🙁 Actual behavior
The code works fine at runtime, but the typescript compiler raises the following error for the Uint8Array | Array<number>
case:
This expression is not callable.
Each member of the union type '{ (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8Array) => number): number; (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8Array) => number, initialValue: number): number; <U>(callbackfn: (previousValue: U, currentValue: numb...' has signatures, but none of those signatures are compatible with each other.(2349)
(property) reduce: {
(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8Array) => number): number;
(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8Array) => number, initialValue: number): number;
<U>(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: Uint8Array) => U, initialValue: U): U;
} | {
...;
}
🙂 Expected behavior
No errors are produced.
Metadata
Metadata
Assignees
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed