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

Internal typings dependency tree is disconnected #6175

Closed
lildeadprince opened this issue Mar 25, 2021 · 3 comments
Closed

Internal typings dependency tree is disconnected #6175

lildeadprince opened this issue Mar 25, 2021 · 3 comments
Labels
TS Issues and PRs related purely to TypeScript issues

Comments

@lildeadprince
Copy link

Bug Report

May be related to #3674 #4511 #4512 #4540
I'm opening the issue since they're either long time closed or have crazy ridiculous advices like "just downgrage, man". And also as a place to describe a possible temporary fix for those who might've had a similar setup.

Current Behavior
Import sub-component like 'rxjs/webSocket', but do not import 'rxjs'.
Partial usage of sub-components does not import all the dependent typing causing into compilation errors.

Expected behavior
If some typing requires some global interface being extended, then this extension should be explicitly defined.
I.e.: type InteropObservable<T> = { [Symbol.observable]: () => Subscribable<T>; } should explicitly import a module which declares Symbol.observable , and so on.
(I am not aware of any other cases, but I do not know whether they exist or not)

Reproduction

import { webSocket as rxSocket } from 'rxjs/webSocket'
export default (url, WebSocketCtor) => rxSocket({ url, WebSocketCtor })

Essentially the import itself will cause the issue but I've added the second line (the usage) just for a convenience. Personally I used it with reconnecting-websocket package (in which funnily I also had to patch some incorrect types).

The error is following

node_modules/rxjs/internal/types.d.ts:45:13 - error TS2339: Property 'observable' does not exist on type 'SymbolConstructor'.

45     [Symbol.observable]: () => Subscribable<T>;
               ~~~~~~~~~~

Environment

  • Runtime: Node 15.11
  • RxJS version: 6.6.6

Possible Solution

The actual cause is obvious: the declaration of Symbol.observable was not imported.
Brief search pinpoints the Rx.d.ts file that contains the required declaration.

The minimal solution is as simple as that:

import 'rxjs'; // just add this line and all necessary typings will be imported
import { webSocket as rxSocket } from 'rxjs/webSocket'
export default (url, WebSocketCtor) => rxSocket({ url, WebSocketCtor })

The workaround is simple, but it is still a workaround and the presence of the issue detects some internal inconsistency in the typings.
So for an actual fix as I mentioned above it'd be better to extract the "global" declarations somewhere and import them where necessary.

@kwonoj kwonoj added the TS Issues and PRs related purely to TypeScript issues label Mar 25, 2021
@cartant
Copy link
Collaborator

cartant commented Mar 26, 2021

Could you include a complete breakdown of the steps necessary to reproduce this and the versions and configurations - e.g. tsconfig.json - required? I cannot reproduce the problem using RxJS 6.6.6 and TypeScript 4.2.3 - using tsc for the build. Also Rx.d.ts and its related files can only used if rxjs-compat is used. Is the problem reproducible only if that package is used?

@lildeadprince
Copy link
Author

Reproduction is as little as I've mentioned originally: just two lines of code.
I've also created now a little repo with it here for you to check https://github.com/lildeadprince/rxjs-symbol-typedef
npm run compile-default for compilation with error
npm run compile-workaround for successful compilation using another import for missing declarations as workaround.

As for the Rx.d.ts I might've confused you, since it was just the first place I found the missing declaration and so I mentioned it. Type imports there very intricate and unfortunately I did not have enough time to investigate it originally.

Correct narrowing down would be probably 'internal/symbol/observable' for now.

@cartant
Copy link
Collaborator

cartant commented Mar 28, 2021

Closed by #6178

@cartant cartant closed this as completed Mar 28, 2021
benlesh pushed a commit that referenced this issue Apr 15, 2021
* fix(symbol): revert unique symbol in #5874

- closes #5919

* fix(types): move Symbol.observable into types.ts (#6178)

Closes #6175

Co-authored-by: Nicholas Jamieson <nicholas@cartant.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TS Issues and PRs related purely to TypeScript issues
Projects
None yet
Development

No branches or pull requests

3 participants