diff --git a/src/utilities/observables/Observable.ts b/src/utilities/observables/Observable.ts index 7a83c20ed34..ac818ec2a94 100644 --- a/src/utilities/observables/Observable.ts +++ b/src/utilities/observables/Observable.ts @@ -8,15 +8,13 @@ export type ObservableSubscription = ZenObservable.Subscription; export type Observer = ZenObservable.Observer; export type Subscriber = ZenObservable.Subscriber; -// Use global module augmentation to add RxJS interop functionality. By -// using this approach (instead of subclassing `Observable` and adding an -// ['@@observable']() method), we ensure the exported `Observable` retains all -// existing type declarations from `@types/zen-observable` (which is important -// for projects like `apollo-link`). -declare global { - interface Observable { - ['@@observable'](): Observable; - } +// The zen-observable package defines Observable.prototype[Symbol.observable] +// when Symbol is supported, but RxJS interop depends on also setting this fake +// '@@observable' string as a polyfill for Symbol.observable. +const { prototype } = Observable; +const fakeObsSymbol = '@@observable' as keyof typeof prototype; +if (!prototype[fakeObsSymbol]) { + prototype[fakeObsSymbol] = function () { return this; }; } -(Observable.prototype as any)['@@observable'] = function () { return this; }; + export { Observable };