Skip to content

Internal typings dependency tree is disconnected #6175

@lildeadprince

Description

@lildeadprince

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    TSIssues and PRs related purely to TypeScript issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions