adaltas / node-stream-transform

Object transformations implementing the Node.js `stream.Transform` API
https://csv.js.org/transform/
49 stars 13 forks source link

Correct Handler types signature; Add generics #30

Closed dnjstrom closed 3 years ago

dnjstrom commented 4 years ago

When updating the package recently in one of my projects, I was surprised that the typescript types didn't seem to match how the transform function behaved. Much like @dvarnai in https://github.com/adaltas/node-stream-transform/pull/27, after some tinkering I figured that the issue stemmed from the fact that the Handler was typed to always receive an array of any where it actually received each element of the records-param/stream in turn.

This PR corrects the signature of the Handler and HandlerCallback to operate on a single element of the records-array, or stream, per call. It also adds some generics to the signature allowing for some extra type safety through inference or manual typing. In the case no type can be inferred the generics will default to use any to stay true to the original signature and not requiring anyone to add types when they upgrade unless they want to.

MichielDeMey commented 3 years ago

I had the same idea of supporting generics to improve typing in this library. Hope we can see a merge in the near future!

wdavidw commented 3 years ago

Sorry, if shall have merge the request. I copy/pasted your changes locally and published instead. Apologies.

wdavidw commented 3 years ago

A new version 2.0.4 includes the fixes