-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
Bug Report
π Search Terms
arraybuffer, narrow, union
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about ArrayBuffer
β― Playground Link
Playground link with relevant code
π» Code
import fs from "node:fs/promises";
async function writeData(data: Uint8Array | ArrayBuffer): Promise<void> {
if (data instanceof ArrayBuffer) {
data = new Uint8Array(data);
}
// Argument of type 'Uint8Array | ArrayBuffer' is not assignable to parameter of type 'string | ArrayBufferView | Iterable<string | ArrayBufferView> | AsyncIterable<string | ArrayBufferView> | Stream'.
// Type 'ArrayBuffer' is not assignable to type 'string | ArrayBufferView | Iterable<string | ArrayBufferView> | AsyncIterable<string | ArrayBufferView> | Stream'.
// Type 'ArrayBuffer' is missing the following properties from type 'Float64Array': BYTES_PER_ELEMENT, buffer, byteOffset, copyWithin, and 24 more.(2345)
await fs.writeFile("./some-file", data);
}
π Actual behavior
Currently ArrayBuffer is not eliminated from the union, so data
being passed to fs.writeFile
is not of the right type.
π Expected behavior
I expected the conditional to remove ArrayBuffer
from the union, making data
's type Uint8Array
(after the conditional).
Offroaders123
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created