A solution has been discovered that allows me to override Node.js advertised Flow ads using internally.
Flow allows you to use the $projectRoot/flow-typed folder to include custom type declarations, which are most often used to include npm shared library declarations.
The same folder can also be used to override some of the types used by the stream inside its standard Node.js library.
I had to create a file called $projectRoot/flow-typed/node.js and copy entire sections from https://github.com/facebook/flow/blob/master/lib/node.js to this file. Copying partial sections does not work because Flow does not support extension of declared types at this time ( https://github.com/facebook/flow/issues/396 .)
For example, take a Transform stream and add arguments of type objectMode to your _transform method. Looks like this -
declare class stream$Transform extends stream$Duplex { _transform( chunk: Buffer | string | Object, encoding: string, callback: (error: ?Error, data?: Buffer | string | Object) => void ): void; _flush( callback: (error: ?Error) => void ): void; }
where is every Buffer | String Buffer | String been replaced by include Object .
The file /flow-typed/node.js managed in version control of the project. But as soon as the newer version of Flow supports the additional syntax in Node.js, this declaration can be removed. Meanwhile, it solves errors in the stream caused by the fact that the stream lags behind Node.js and its general incorrectness.
source share