From 78106a265a358ee6af1b7f154763ffe63f1226ed Mon Sep 17 00:00:00 2001 From: Emily M Klassen Date: Thu, 9 May 2024 18:17:20 -0700 Subject: [PATCH 1/2] test: add dtslint check for interop --- spec-dtslint/helpers.ts | 32 ++++++++++++++++++++++++++++++++ spec-dtslint/types-spec.ts | 7 ++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/spec-dtslint/helpers.ts b/spec-dtslint/helpers.ts index 107e0e20b4..effc449c66 100644 --- a/spec-dtslint/helpers.ts +++ b/spec-dtslint/helpers.ts @@ -32,3 +32,35 @@ export const g$ = of(new G()); export const h$ = of(new H()); export const i$ = of(new I()); export const j$ = of(new J()); + +interface Subscription { + closed: boolean; + unsubscribe(): void; +} +interface SubscriptionObserver { + closed: boolean; + next(value: T): void; + error(errorValue: any): void; + complete(): void; +} +type Subscriber = (observer: SubscriptionObserver) => void | (() => void) | Subscription; + +interface Observer { + start?(subscription: Subscription): any; + next?(value: T): void; + error?(errorValue: any): void; + complete?(): void; +} + +export declare class CompatObservable { + constructor(subscriber: Subscriber); + + subscribe(observer: Observer): Subscription; + subscribe( + onNext: (value: T) => void, + onError?: (error: any) => void, + onComplete?: () => void, + ): Subscription; + + [Symbol.observable](): CompatObservable; +} diff --git a/spec-dtslint/types-spec.ts b/spec-dtslint/types-spec.ts index ef7aab679c..781e4cc29b 100644 --- a/spec-dtslint/types-spec.ts +++ b/spec-dtslint/types-spec.ts @@ -7,7 +7,7 @@ import { Head, Tail } from 'rxjs'; -import { A, B, C } from './helpers'; +import { A, B, C, CompatObservable } from './helpers'; describe('ObservedValueOf', () => { it('should infer from an observable', () => { @@ -24,6 +24,11 @@ describe('ObservedValueOf', () => { let explicit: ObservedValueOf>; let inferred = explicit!; // $ExpectType A }); + + it('should infer from an compatible observable', () => { + let explicit: ObservedValueOf>; + const inferred = explicit!; // $ExpectType A + }); }); describe('ObservedUnionFromArray', () => { From 293ff154bf67f54c002dda9372e46d2eaf3ee8c1 Mon Sep 17 00:00:00 2001 From: Emily M Klassen Date: Thu, 9 May 2024 18:19:01 -0700 Subject: [PATCH 2/2] fix(types): improve interop with zen observable --- src/internal/types.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/internal/types.ts b/src/internal/types.ts index b72eab3a11..52964cc910 100644 --- a/src/internal/types.ts +++ b/src/internal/types.ts @@ -97,6 +97,11 @@ export interface Subscribable { subscribe(observer: Partial>): Unsubscribable; } +export interface InteropSubscribable { + subscribe(observer: Partial>): Unsubscribable; + subscribe(onNext?: (value: T) => void, onError?: (error: any) => void, onComplete?: () => void): Subscription; +} + /** * Valid types that can be converted to observables. */ @@ -118,7 +123,7 @@ export type ObservableLike = InteropObservable; * An object that implements the `Symbol.observable` interface. */ export interface InteropObservable { - [Symbol.observable]: () => Subscribable; + [Symbol.observable]: () => Subscribable | InteropSubscribable; } /* NOTIFICATIONS */