Rxjs: New pipe operators in 5.5 fail in TS < 2.4 as they don't transfer type

Created on 24 Sep 2017  路  9Comments  路  Source: ReactiveX/rxjs

RxJS version:

RxJS 5.5.0-beta.0
TypeScript 2.3

Code to reproduce:

Quite the same example as in lettable operators doc :

const source$ = range(0, 10);

source$.pipe(
  filter(x => x % 2 === 0),
  map(x => x.toFixed())
)
.subscribe(x => console.log(x));

Expected behavior:

It should work.

Actual behavior:

On TypeScript compilation, it fails with this error :

ERROR: Property 'toFixed' does not exist on type '{}'.

Meaning the type (here number) is not transferred by the pipe operator. The pipe operator seems to default back to {} all the time.

Additional information:

It works starting TypeScript 2.4+.

If this is normal, it should at least be indicated in the CHANGELOG, as it's an unexpected (breaking ?) change for a minor update.

Most helpful comment

@cyrilletuzi we DO follow semver... the lettable operators are all _new features_ and all existing features have not changed.

You can still use import 'rxjs/add/operator/map'; etc in your apps with 5.5.0-beta and EVERY version of 5.x.

:)

There are no breaking changes in 5.5.0

Type inference through these functions simply isn't supported by TypeScript < 2.4, but that's not something RxJS can control. There are, in fact, large groups of people that don't even use TS with RxJS. We love TS and we want to support it as much as possible, but we're not going to exclude features because older versions of TypeScript don't handle them well.

All 9 comments

Hi :)
Have you considered updating TypeScript? The current version is 2.5

If it was just dependent on me I would, but for now Angular is stuck to TypeScript 2.3 due to the breaking changes of TS 2.4. ;)

In that case, how about using a previous version of RxJS?

What about following semver ?

I wouldn't mind using a previous version of RxJS if semver was followed. What will happen in real world is that once RxJS 5.5 is released, new Angular projects (or any project using RxJS) will install RxJS 5.5 due to semver rules, and it will break in these cases. Or we'll have to pin RxJS version and add more complicated configuration like we already have to do for TS for the exact same reason.

By the way, notice my issue doesn't even ask for all of that. I suppose everyone is now used to quite no one really following semver. It just asks to at least write it in the docs so users know it.

TypeScript issues non-semver versions, that's the root problem.

I myself don't publish versions for RxJS.

@cyrilletuzi we DO follow semver... the lettable operators are all _new features_ and all existing features have not changed.

You can still use import 'rxjs/add/operator/map'; etc in your apps with 5.5.0-beta and EVERY version of 5.x.

:)

There are no breaking changes in 5.5.0

Type inference through these functions simply isn't supported by TypeScript < 2.4, but that's not something RxJS can control. There are, in fact, large groups of people that don't even use TS with RxJS. We love TS and we want to support it as much as possible, but we're not going to exclude features because older versions of TypeScript don't handle them well.

I'm having the same problem, using typescript 2.5.0 and 2.8.0
Types inside the pipe function are always Observable<{}>
RxJs version 5.5.10

Does anyone have any suggestions, except for casting everywhere manually?

UPDATE: It's an IDE problem

Same here but with static merge function. I'm not able to type this correctly...
RxJs: 6.0.0
IDE: Webstorm

import {merge, of} from 'rxjs
merge(of(1), of(2));

It always takes following override:

export declare function merge<T>(v1: ObservableInput<T>, scheduler?: SchedulerLike): Observable<T>;

the only way for me to get this working is a dirty hack, using the spread operator...

merge(...[of(1), of(2)]);

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dooreelko picture dooreelko  路  3Comments

cartant picture cartant  路  3Comments

cartant picture cartant  路  3Comments

LittleFox94 picture LittleFox94  路  3Comments

Agraphie picture Agraphie  路  3Comments