🔎 Search Terms
overload overloaded function parameter union type
🕗 Version & Regression Information
- This changed between versions 5.8.3 and 5.9.3
- This changed in commit or PR _______
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
- I was unable to test this on prior versions because _______
⏯ Playground Link
https://www.typescriptlang.org/play/?ts=5.9.3#code/GYVwdgxgLglg9mABAIwIYCcAUATVVUBciAguuqgJ4BCIwwApugJRHjb3Axj3YDcAUKEiwEKDDjyFEAVS5QAHKXIUWiNhy48BQ6PCRosufESWUadRogA+MuYrKUmiAN79EidPSgh0YAQF9+QXBdUWA4OAljNTAAazA4AHcwJ1d3GGBETABCKNRELgBnfEh6OEzZMAVTCmsbI3yikogyzJrzBmYnT29fAXcDPKYAoA
💻 Code
function bar(data: ArrayBuffer): undefined;
function bar(data: Uint8Array): undefined;
function bar(data: ArrayBuffer | Uint8Array) {
return;
}
function foo(data: unknown) {
if (!(data instanceof Uint8Array || data instanceof ArrayBuffer)) return;
bar(data);
}
🙁 Actual behavior
Got the following error in 5.9.3, but works perfectly in 5.8.3:
No overload matches this call.
Overload 1 of 2, '(data: ArrayBuffer): undefined', gave the following error.
Argument of type 'ArrayBuffer | Uint8Array<ArrayBufferLike>' is not assignable to parameter of type 'ArrayBuffer'.
Type 'Uint8Array<ArrayBufferLike>' is not assignable to type 'ArrayBuffer'.
The types of 'slice(...)[Symbol.toStringTag]' are incompatible between these types.
Type '"Uint8Array"' is not assignable to type '"ArrayBuffer"'.
Overload 2 of 2, '(data: Uint8Array<ArrayBufferLike>): undefined', gave the following error.
Argument of type 'ArrayBuffer | Uint8Array<ArrayBufferLike>' is not assignable to parameter of type 'Uint8Array<ArrayBufferLike>'.
Type 'ArrayBuffer' is missing the following properties from type 'Uint8Array<ArrayBufferLike>': BYTES_PER_ELEMENT, buffer, byteOffset, copyWithin, and 23 more.
🙂 Expected behavior
Compiles without error
Additional information about the issue
This test case was isolated from https://github.com/brianc/node-postgres/blob/77cb77150d6c0f07b0aa2134c6b3ef0cb80335c1/packages/pg-cloudflare/src/index.ts#L156, while working on brianc/node-postgres#3662.
🔎 Search Terms
overload overloaded function parameter union type
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play/?ts=5.9.3#code/GYVwdgxgLglg9mABAIwIYCcAUATVVUBciAguuqgJ4BCIwwApugJRHjb3Axj3YDcAUKEiwEKDDjyFEAVS5QAHKXIUWiNhy48BQ6PCRosufESWUadRogA+MuYrKUmiAN79EidPSgh0YAQF9+QXBdUWA4OAljNTAAazA4AHcwJ1d3GGBETABCKNRELgBnfEh6OEzZMAVTCmsbI3yikogyzJrzBmYnT29fAXcDPKYAoA
💻 Code
🙁 Actual behavior
Got the following error in 5.9.3, but works perfectly in 5.8.3:
🙂 Expected behavior
Compiles without error
Additional information about the issue
This test case was isolated from https://github.com/brianc/node-postgres/blob/77cb77150d6c0f07b0aa2134c6b3ef0cb80335c1/packages/pg-cloudflare/src/index.ts#L156, while working on brianc/node-postgres#3662.