5 beta 11
The typings for Observable.create simply return Function. Should they instead return Observable with a generic?
Unfortunately can't by Typescript doesn't support reference class type parameters from static methods. It is not complete precise definition but limitation to work with TypeScript's syntax. If there's workable proposal supports better typing that have been missing, it's always welcome.
/cc @david-driscoll as well. AFAIK I don't see neat way to support this, but I could be wrong - adding for visibility.
There isn't a great way to support this until https://github.com/Microsoft/TypeScript/issues/4628 (PR https://github.com/Microsoft/TypeScript/pull/6381) is merged in.
It's possible to support it... but it would be a very large painful effort based on the existing api.
Seems given PR for compiler side support does not have immediate foreseeable milestones yet, I think there's few rooms in codebase to fix this behavior. Instead of handcrafting based on current limitation, rather visit later once have proper compiler support seems more feasible option for me, closing this issue for now and reopen. What do you think? @david-driscoll @OliverJAsh
Seems it works in [email protected] write like below
class Observable<T> {
static create<T>(): Observable<T>
}
returning Function will broken type check.
So I have to ignore them in my bundle helper (https://github.com/morlay/my-rx-addons) 馃槩
I changed @reactivex/rxjs/dist/cjs/Observable.d.ts like below:
// add this:
import { Observer } from './Observer';
//...
// change this:
// static create: Function;
// to:
static create: (subscribe: (observer: Observer<T>) => void) => Observable<T>;
It works for me.
Am I doing this right?
Update:
The official doc used Observable.create method on the very first page, I think it's important that we can fix this typing issue.
It really comes down to a conflict between Observable.create and Subject.create since Subject inherits from Observable. There may be some wacky work around, that we can do after the build to make it work, so perhaps we should investigate those. However it would be much better if we had language level support for this 馃槥.
I'm marking this as upstream related, as this isn't really easy changes with current support of compiler we're using. I'll leave issue opened since problem's still there, but probably won't have immediate support for this at this moment.
It's worth noting that Observable.create(subscribe) does exactly the same thing as new Observable(subscribe) so to get the correct typings you're better off just avoiding Observable.create
In the end, people should just be using new Observable, however, in the case of Subject.create, I think we need to export a standalone function that does what that does.
I think we can close this issue, though. As it's no longer valid.
Most helpful comment
It's worth noting that
Observable.create(subscribe)does exactly the same thing asnew Observable(subscribe)so to get the correct typings you're better off just avoidingObservable.create