Skip to content

BehaviorSubject private _value property typings issue #2156

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

Closed
paralin opened this issue Nov 24, 2016 · 8 comments
Closed

BehaviorSubject private _value property typings issue #2156

paralin opened this issue Nov 24, 2016 · 8 comments

Comments

@paralin
Copy link

paralin commented Nov 24, 2016

RxJS version:

5.0.0-rc.4

Code to reproduce:

I will make a code reproduction repo... At the moment it's a bit challenging to do so due to the nature of the bug (multiple packages compiled with emitted definitions).

Multiple packages reference rxjs 5.0.0-rc.4. Package A declares a enum WindowState and an interface IWindow which has a field state that is a BehaviorSubject<WindowState>. Package B implements IWindow properly by referencing package A. Package C references both packages A and B, and experiences the below error when trying to use the implementation of IWindow from package B.

The _value field on BehaviorSubject is private anyway and doesn't have any type associated with it (not even T).

Expected behavior:

The type error on _value should not be happening.

Actual behavior:

  Types of property 'state' are incompatible.
    Type 'BehaviorSubject<WindowState>' is not assignable to type 'BehaviorSubject<WindowState>'.
      Types have separate declarations of a private property '_value'.

Additional information:

I started noticing this in the upgrade from rc.3 to rc.4. Something changed with _value in this time.

This happens both with using npm install and yarn install. The difference of course being that yarn is very aggressive about flattening the tree, so every package will end up using the same version of rxjs.

Packages A and B are both compiled to JavaScript with emitted TypeScript definitions on TypeScript version 2.1.1.

@paralin
Copy link
Author

paralin commented Nov 24, 2016

Note: I've been struggling with this for the last few days, trying to find why it's happening. Issue filing here is a last resort, but I'm pretty sure there's something odd going on in rxjs OR typescript causing this.

@kwonoj
Copy link
Member

kwonoj commented Nov 24, 2016

I'm suspecting there may be duplicated packages with different version (i.e, rc.xx, rc.4) between dependencies, or either there's linked package (#1744). If you can, I'd like to suggest to start from wipe out all node_modules, ensure only one rc.4 packages are installed.

@paralin
Copy link
Author

paralin commented Nov 24, 2016

I've just tried that:

rm -rf node_modules/
rm yarn.lock
yarn

as well as the same using npm install.

rxjs is tightly locked to rc.4, as well (no semantic version range).

I double checked all the upstream packages are compiled against rc.4 too with a strong version lock (packages A and B).

Strange. I'll go back and double check everything again.

@kwonoj
Copy link
Member

kwonoj commented Nov 24, 2016

Just in case, please try with npm only instead of yarn to isolate completely, then check manually inside of node_modules (like npm la, etcs) to see what version of rxjs is installed.

@paralin
Copy link
Author

paralin commented Nov 24, 2016

Okay, done. Finally found the culprit. One random package one of my upstream deps of A referenced has rxjs at .3. Ouch.

I really wish rxjs did not emit _value in the typings. I understand why TypeScript emits private fields, but this seems incorrect somehow. Could it instead be _value<T> or something similar to avoid this error?

If there's no way to fix this awkward problem, feel free to close. I've fixed my issue, but it'd be great if we could figure out some kind of general fix.

@kwonoj
Copy link
Member

kwonoj commented Nov 24, 2016

Could it instead be _value or something similar to avoid this error?

: Unfortunately I don't think we have those level of control to emit specifics. If you refer actual code (

constructor(private _value: T) {
), it's simply constructor(private _value: T) have generic type only, but compiler does some magic inside to create internals.

There are continuous effort to improve type definitions over though to resolve inconveniences regarding type definitions. Let me close this issue for now as issue itself is resolved.

@kwonoj kwonoj closed this as completed Nov 24, 2016
@paralin
Copy link
Author

paralin commented Nov 24, 2016

Thanks for your help @kwonoj

@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

2 participants