Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why different generics for Subscriber and Observable #2166

Closed
donaldpipowitch opened this issue Dec 1, 2016 · 5 comments · Fixed by #2196
Closed

Why different generics for Subscriber and Observable #2166

donaldpipowitch opened this issue Dec 1, 2016 · 5 comments · Fixed by #2196
Labels
TS Issues and PRs related purely to TypeScript issues

Comments

@donaldpipowitch
Copy link

Not sure if this is a bug or not.

RxJS version:

5.0.0-rc.4

Code to reproduce:

static create: Function = <T>(subscribe?: <R>(subscriber: Subscriber<R>) => TeardownLogic) => {

Expected behavior:

  static create: Function = <T>(subscribe?: <T>(subscriber: Subscriber<T>) => TeardownLogic) => {
    return new Observable<T>(subscribe);
  };

Actual behavior:

  static create: Function = <T>(subscribe?: <R>(subscriber: Subscriber<R>) => TeardownLogic) => {
    return new Observable<T>(subscribe);
  };

Additional information:

Maybe I misunderstood this part of RxJS, but I thought the Observable and Subscriber would share the same generic type here? Aren't the values I pass to subscriber.next from the same type I get when I use value$.map?

@kwonoj kwonoj added the TS Issues and PRs related purely to TypeScript issues label Dec 13, 2016
@kwonoj
Copy link
Member

kwonoj commented Dec 13, 2016

Actually I lost history in my memory for background of this - /cc @david-driscoll : any idea?

@david-driscoll
Copy link
Member

that looks odd at first glance and probably needs to be changed.

that said since subject has a different create method than observable the typings mean nothing as it only has a function type.

@benlesh
Copy link
Member

benlesh commented Dec 15, 2016

Looks incorrect to me.

@josh-sachs
Copy link

josh-sachs commented Feb 18, 2017

I came across this because I'm experiencing an issue where Typescript is not properly resolving the return type for Observable.create.

static create: Function = <T>(subscribe?: <T>(subscriber: Subscriber<T>) => TeardownLogic) => {
    return new Observable<T>(subscribe);
};

I think assigning create the global Function type is the issue. I believe this would resolve it...

static create = <T>(subscribe?: <T>(subscriber: Subscriber<T>) => TeardownLogic) => {
    return new Observable<T>(subscribe);
};

@lock
Copy link

lock bot commented Jun 6, 2018

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.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
TS Issues and PRs related purely to TypeScript issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants