facebook / flow

Adds static typing to JavaScript to improve developer productivity and code quality.
https://flow.org/
MIT License
22.07k stars 1.85k forks source link

Node.js Writable Stream can write Uint8Array #4938

Open calrsom opened 7 years ago

calrsom commented 7 years ago

stream$Writable.write chunk argument should include Uint8Array and can take any non-null value for object-mode streams according to Node documentation.

https://github.com/facebook/flow/blob/5c9deb498ca0b523243a8fda40160333f1f23277/lib/node.js#L1439

See: https://nodejs.org/api/stream.html#stream_writable_write_chunk_encoding_callback;

calrsom commented 7 years ago

I see now that this was added in Node 8; I'm not sure how flow handles versions, so maybe this isn't quite a bug.

jcready commented 7 years ago

For the Uint8Array, but object-mode streams have been around since node v0.9.4. It's definitely something that should be addressed.

dmeehan1968 commented 6 years ago

This affects multiple method definitions of Stream classes - push, write etc are all defined as Buffer | string which causes problems in object mode streams where 'any' is valid.

popham commented 5 years ago

I've got a ((someUint8Array: any): Buffer) cast in some test code, and while diagnosing something else I overrode my path to grab a particular Node version, v8.14.1-linux-x64. I got a

TypeError: Invalid data, chunk must be a string or buffer, not object

I too thought that streams switched to accept Uint8Array at version 8, but try a require("child_process").spawn("ls").stdin.write(new Uint8Array(0)) to see for yourself. My 10.14.2 version handles it fine, though.