Reactive-Extensions / RxJS

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

Compilation fails with TypeScript 2.4 #1487

Open evmar opened 7 years ago

evmar commented 7 years ago
95         return new PromiseObservable<T>(ish, scheduler);
                                           ~~~

third_party/javascriptnode_modules/rxjs/v5_2_0/src/observable/FromObservable.ts(95,41): error TS2345: Argument of type '(Subscribable<T> & Promise<{}>) | (PromiseLike<T> & Promise<{}>) | (ArrayLike<T> & Promise<{}>)' is not assignable to parameter of type 'Promise<T>'.
  Type 'Subscribable<T> & Promise<{}>' is not assignable to type 'Promise<T>'.
    Types of property 'then' are incompatible.
      Type '<TResult1 = {}, TResult2 = never>(onfulfilled?: (value: {}) => TResult1 | PromiseLike<TResult1>, ...' is not assignable to type '<TResult1 = T, TResult2 = never>(onfulfilled?: (value: T) => TResult1 | PromiseLike<TResult1>, on...'.
        Types of parameters 'onfulfilled' and 'onfulfilled' are incompatible.
          Types of parameters 'value' and 'value' are incompatible.
            Type '{}' is not assignable to type 'T'.
70   return (operator.caught = caught);
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

third_party/javascript/node_modules/rxjs/v5_2_0/src/operator/catch.ts(70,3): error TS2322: Type 'Observable<{}>' is not assignable to type 'Observable<R>'.
  Type '{}' is not assignable to type 'R'.
70   return (operator.caught = caught);
             ~~~~~~~~~~~~~~~

third_party/javascript/node_modules/rxjs/v5_2_0/src/operator/catch.ts(70,11): error TS2322: Type 'Observable<{}>' is not assignable to type 'Observable<T>'.
  Type '{}' is not assignable to type 'T'.
41   return this.lift(new DefaultIfEmptyOperator(defaultValue));
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

third_party/javascript/node_modules/rxjs/v5_2_0/src/operator/defaultIfEmpty.ts(41,3): error TS2322: Type 'Observable<{} | R>' is not assignable to type 'Observable<T | R>'.
  Type '{} | R' is not assignable to type 'T | R'.
    Type '{}' is not assignable to type 'T | R'.
      Type '{}' is not assignable to type 'R'.
benlesh commented 7 years ago

cc @david-driscoll

benlesh commented 7 years ago

@evmar you should try 6.0.0-alpha.0, it targets TS 2.3. (in the next branch)

Igorbek commented 7 years ago

isn't this rxjs 4 repo?

david-driscoll commented 7 years ago

Sounds like it's related to https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#typescript-24 without digging into it much.

This appears to be revealing a few issues like not giving the full type DefaultIfEmptyOperator and a few other bits. That said using rxjs as a library shouldn't have a big impact if you're using it as a module, not compiling it as a third party.

DanielRosenwasser commented 7 years ago

Also related to the 2.4 changes is https://github.com/Microsoft/TypeScript/issues/16593.

amcdnl commented 7 years ago

I'm getting these on 2.4.1 now:

[at-loader] ./node_modules/rxjs/Subject.d.ts:16:22
    TS2415: Class 'Subject<T>' incorrectly extends base class 'Observable<T>'.
  Types of property 'lift' are incompatible.
    Type '<R>(operator: Operator<T, R>) => Observable<T>' is not assignable to type '<R>(operator: Operator<T, R>) => Observable<R>'.
      Type 'Observable<T>' is not assignable to type 'Observable<R>'.
        Type 'T' is not assignable to type 'R'.

[at-loader] ./node_modules/rxjs/observable/dom/WebSocketSubject.d.ts:24:22
    TS2415: Class 'WebSocketSubject<T>' incorrectly extends base class 'AnonymousSubject<T>'.
  Types of property 'lift' are incompatible.
    Type '<R>(operator: Operator<T, R>) => WebSocketSubject<R>' is not assignable to type '<R>(operator: Operator<T, R>) => Observable<T>'.
      Type 'WebSocketSubject<R>' is not assignable to type 'Observable<T>'.
        Types of property 'operator' are incompatible.
          Type 'Operator<any, R>' is not assignable to type 'Operator<any, T>'.
            Type 'R' is not assignable to type 'T'.

@benlesh - is the recommended solution to not upgrade at this point?

paulpdaniels commented 7 years ago

@evmar @amcdnl @benlesh should this be moved over to ReactiveX/rxjs? I think having this here is going to be confusing for incoming readers.

benlesh commented 7 years ago

Yes.

joechlanda commented 7 years ago

Ran into the same issue just now, downgrading typescript for now resolve the compilation error. Glad I came across this issue 👍

paulpdaniels commented 7 years ago

@evmar or @mattpodwysocki do you mind closing?

evmar commented 7 years ago

Sorry, I lack context. Is the issue fixed?

DanielRosenwasser commented 7 years ago

My understanding is that the issue will be fixed in RxJS 6.0. The signature hasn't been corrected in 5.x.

paulpdaniels commented 7 years ago

This issue is not related to this repository. RxJS 5 and later is a different repository. See my link earlier, I'm trying to minimize people coming here and expecting to get help on a repo that is in maintenance mode.

claudiuconstantin commented 7 years ago

I'm confused about the whole ReactiveX/rxjs vs Reactive-Extensions/RxJS thing. Better descriptions for the two repositories would be very helpful.

benlesh commented 7 years ago

@claudiuconstantin There are now warnings/notices all over the RxJS 4 readme and docs (reactive-extensions)

Everyone else: This issue has been solved by RxJS 5.4.2

raysuelzer commented 6 years ago

I do not see that it is resolved at all. Observable and Subject are still not assignable. Type 'Observable' is not assignable to type 'AsyncSubject'.

benlesh commented 6 years ago

@mattpodwysocki can you please close this, as we're in the wrong repo lol

@raysuelzer ... you've got a classic typed-language problem there... AsyncSubject inherits from Observable, not the other way around. So you can't pass an Observable where AsyncSubject is expected.

yamidvo commented 6 years ago

I have an error in switchMap operator:

export class AvailableStoreTypesLoadedEffect {
constructor(private actions$: Actions,
          private service: AvailableService) {

}

 @Effect()
 AvailableStoreTypesLoadedEffect$ = this.actions$
 .ofType(FETCH_AVAILABLE_STORE_TYPES)
 .pipe(
   switchMap(action => this.service.fetchAvailableStoreTypes()),//Error:(22, 9) TS2684:The 'this' context of type 'void' is not assignable to method's 'this' of type 'Observable<{}>'.
   map(res => new AvailableStoreTypesLoaded(res))
  );
}

I tried with:

Observable.of({})
  .pipe(
    switchMap(() => Observable.of({}))//Error:(22, 9) TS2684:The 'this' context of type 'void' is not assignable to method's 'this' of type 'Observable<{}>'.
  );

but I get the same error.

My environment is:

angular 5.0.3
typescript 2.4.2
rxjs 5.5.2
paulpdaniels commented 6 years ago

@yamidvo Please see the above conversation. This repo does not support RxJS 5 and above.