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

npm linking consumer with library causes TS2322: Observable not assignable to Observable #1744

Closed
vankeer opened this issue Jun 6, 2016 · 9 comments

Comments

@vankeer
Copy link

vankeer commented Jun 6, 2016

RxJS version: 5.0.0-beta.6 and also tried npm linking with master today - no change

Code to reproduce:

You need:

  • A library that exposes a method returning an Observable (example)
  • A consumer that consumes this method and returns an Observable as well (example)
  • npm link the two before building

Example:

git clone https://github.com/vankeer/ng2-example-library.git
cd ng2-example-library
npm i
npm link
cd ..

git clone https://github.com/vankeer/ng2-example-consumer
cd ng2-example-consumer
npm i
npm link ng2-example-library
gulp build.dev

Expected behavior:

The library and the consumer build normally.

Actual behavior:

The consumer throws this error:

src\client\app+wiki\wiki.component.ts(33,12): error TS2322: Type 'Observable<any[]>' is not assignable to type 'Observable<any[]>'.
Property 'source' is protected but type 'Observable' is not a class derived from 'Observable'.

Additional information:

This only happens when npm linking the repos.

One way to avoid this problem is by having rxjs methods return an interface for Observable instead of Observable. Of course, this would require a rather large refactoring. PR for this suggested change: #1741

Another way to avoid the problem is by explicitly installing the typings in the consumer (have not managed to do this yet with this specific example though).

@benlesh
Copy link
Member

benlesh commented Jun 8, 2016

It's probably that both libraries should have rxjs as a peer dependency, rather than a direct dependency. You'd run into this issue with any library that passed through a type like that. I'm not sure there's anything rxjs can do about it.

@vankeer
Copy link
Author

vankeer commented Jun 15, 2016

Unfortunately having rxjs as peer dependency does not fix this problem. I updated my example repos.

I am unsure how to fix this (besides explicitly installing typings in the consumer) and I don't quite understand why this is not an issue for more people? Aren't more people npm linking different libraries like this and running into this same problem? Not sure what I'm missing.

@benlesh
Copy link
Member

benlesh commented Jun 17, 2016

@vankeer oh, to clarify, this is a TypeScript build failure? cc/ @david-driscoll

@david-driscoll
Copy link
Member

I believe it's an issue with the compiler still. I get the issue as well.

Work around is pretty easy, at least for working locally. Just make a
node_modules in the parent directory and put rxjs and symbol observable in
there. Less than ideal but it works for now.

I'll test with typescript@next and see if its been resolved.
On Thu, Jun 16, 2016 at 8:57 PM Ben Lesh notifications@github.com wrote:

@vankeer https://github.com/vankeer oh, to clarify, this is a
TypeScript build failure? cc/ @david-driscoll
https://github.com/david-driscoll


You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
#1744 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/ABNdpYMcDd2GhmHO0Xk0I-f7lhm1Zk-Aks5qMfDegaJpZM4IuuAe
.

Thanks,
David

@vankeer
Copy link
Author

vankeer commented Jun 17, 2016

@Blesh Yup, it's a Typescript build failure. Thanks for following up this issue

@david-driscoll Thanks for your response. Using typescript@next did not solve the issue for me. Also, I'm not sure what you mean with installing rxjs and symbol-observable in the parent dir to fix the issue, since that alone is not enough to fix it for me. But, deleting [consumer]/node_modules/[library]/node_modules/rxjs does solve the issue for me, since Typescript will then rely on [consumer]/node_modules/rxjs for typings I guess. I thought that should be the behavior when specifying rxjs as peerDependency, but it's not apparently.

It's a bit of a hassle, especially when working with lots of libraries, but it's another workaround for this issue, other than installing typings explicitly.

@david-driscoll
Copy link
Member

This may be a decent case to give a change like #1741 a second look.

@fredrikbonander
Copy link

I think this microsoft/TypeScript#6496 is related, unclear if it's gonna be fixed from the TS side.

@kwonoj
Copy link
Member

kwonoj commented Oct 28, 2016

As similar to #2092 I don't think there's viable option on RxJS codebase side at this moment, rather to wait compiler side update and close this issue. /cc @Blesh for visibility, please reopen if needed.

@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
None yet
Projects
None yet
Development

No branches or pull requests

5 participants