Closed dnjstrom closed 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!
Sorry, if shall have merge the request. I copy/pasted your changes locally and published instead. Apologies.
A new version 2.0.4 includes the fixes
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 therecords
-param/stream in turn.This PR corrects the signature of the
Handler
andHandlerCallback
to operate on a single element of therecords
-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 useany
to stay true to the original signature and not requiring anyone to add types when they upgrade unless they want to.