Member-only story

RxJS: Improving the Static pipe Function

Nicholas Jamieson
3 min readMay 21, 2018

--

Photo by Angelina Litvin on Unsplash

My previous article looked at using the static pipe function to compose reusable combinations of operators.

Most of the time, the pipe function’s TypeScript overload signatures will infer the desired type for the returned function. However, sometimes it’s desirable to have a generic type inferred and the current overload signatures will not do that.

Let’s look at why you might want a generically-typed function to be returned and what needs to be changed for that to happen.

Specifically-typed operators

The static pipe function can be used to compose a reusable, debouncing operator that can be used with the changes emitted by input elements:

The static pipe function does not have a source observable, so there is nothing from which the first type parameter can be inferred.

If an explicit type parameter is not specified, it will be inferred as {} — an empty interface — because that’s how TypeScript behaves if a type parameter is not specified and cannot be inferred.

--

--

Nicholas Jamieson
Nicholas Jamieson

Written by Nicholas Jamieson

RxJS core team member; front-end developer; mentor; speaker; open-source contributor

No responses yet