Reactive-Extensions / RxJS

The Reactive Extensions for JavaScript
http://reactivex.io
Other
19.49k stars 2.1k forks source link

Upgrading from 5.3.0 to 5.4.0 breaks TS compilation #1485

Closed 0x-r4bbit closed 7 years ago

0x-r4bbit commented 7 years ago

Hi everyone,

I ran into a regression when upgrading from RxJS 5.3.0 to 5.4.0 in my Angular project. Basically, I have a class that looks like:

export class LabResolver implements Resolve<Lab> {

  resolve(route: ActivatedRouteSnapshot): Observable<Lab> {
    ...
  }
}

Regardless of what this class does, this compiled perfectly with 5.3.0. When I upgrade to 5.4.0 I'm getting the following TS error:

Class 'LabResolver' incorrectly implements interface 'Resolve<Lab>'.
  Types of property 'resolve' are incompatible.
    Type '(route: ActivatedRouteSnapshot) => Observable<Lab>' is not assignable to type '(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) => Lab | Observable<Lab> | Promise<Lab>'.
      Type 'Observable<Lab>' is not assignable to type 'Lab | Observable<Lab> | Promise<Lab>'.
        Type 'Observable<Lab>' is not assignable to type 'Promise<Lab>'.
          Property 'then' is missing in type 'Observable<Lab>'.

I looked into the changelog to see if there's anything that might be related. The only thing I could think of was https://github.com/ReactiveX/RxJS/commit/ade1fd5, however this is just me speculating here.

Maybe another important information: This basically happens in all "resolver" classes. Apart from resolvers being an Angular specific context, I think it boils down to the fact that a resolver's resolve() method always returns: any | Observable<any> | Promise<any>, where any is what ever you put into the Resolve<T> generic.

I hope this is the right place to ask for help.

Thanks!

0x-r4bbit commented 7 years ago

Quick update:

I double-checked if it has something to do with the TS version I'm using. I was on 2.2.2 upgraded to 2.3.4 but getting exactly the same errors.

I'm sure I'm missing something..

0x-r4bbit commented 7 years ago

Oups wrong repo. New issue is here: https://github.com/ReactiveX/rxjs/issues/2659