@@ -14,6 +14,20 @@ export interface NextObserver<T, E, C> {
1414 complete ?: ( res : C ) => void
1515}
1616
17+ export interface ErrorObserver < T , E , C > {
18+ next ?: ( value : T ) => void
19+ error : ( err : E ) => void
20+ complete ?: ( res : C ) => void
21+ }
22+
23+ export interface CompletionObserver < T , E , C > {
24+ next ?: ( value : T ) => void
25+ error ?: ( err : E ) => void
26+ complete : ( res : C ) => void
27+ }
28+
29+ export type PartialObserver < T , E , C > = NextObserver < T , E , C > | ErrorObserver < T , E , C > | CompletionObserver < T , E , C >
30+
1731export interface IUnsubscribable {
1832 /** 取消 observer 的订阅 */
1933 unsubscribe ( ) : void
@@ -27,10 +41,11 @@ export interface ISubscriptionLike extends IUnsubscribable {
2741export type TeardownLogic = ( ) => void
2842
2943export interface ISubscribable < T , E , C > {
30- subscribe ( observer ?: NextObserver < T , E , C > ) : IUnsubscribable
31- subscribe ( next : null | undefined , error : null | undefined , complete : ( res : C ) => void ) : IUnsubscribable
32- subscribe ( next : null | undefined , error : ( error : E ) => void , complete ?: ( res : C ) => void ) : IUnsubscribable
33- subscribe ( next : ( value : T ) => void , error : null | undefined , complete : ( res : C ) => void ) : IUnsubscribable
44+ subscribe (
45+ observer ?: PartialObserver < T , E , C > | ( ( value : T ) => void ) ,
46+ error ?: ( error : any ) => void ,
47+ complete ?: ( ) => void
48+ ) : IUnsubscribable
3449}
3550
3651/** 表示可清理的资源,比如 Observable 的执行 */
@@ -68,7 +83,7 @@ export class Subscriber<T, E, C> extends Subscription implements IObserver<T, E,
6883 protected destination : Partial < IObserver < T , E , C > >
6984
7085 constructor (
71- observerOrNext ?: NextObserver < T , E , C > | ( ( value : T ) => void ) | null ,
86+ observerOrNext ?: PartialObserver < T , E , C > | ( ( value : T ) => void ) | null ,
7287 error ?: ( ( err : E ) => void ) | null ,
7388 complete ?: ( ( res : C ) => void ) | null
7489 ) {
@@ -120,12 +135,12 @@ export class Observable<T, E, C> implements ISubscribable<T, E, C> {
120135
121136 constructor ( private _subscribe : ( subscriber : Subscriber < T , E , C > ) => TeardownLogic ) { }
122137
123- subscribe ( observer : NextObserver < T , E , C > ) : Subscription
138+ subscribe ( observer : PartialObserver < T , E , C > ) : Subscription
124139 subscribe ( next : null | undefined , error : null | undefined , complete : ( res : C ) => void ) : Subscription
125140 subscribe ( next : null | undefined , error : ( error : E ) => void , complete ?: ( res : C ) => void ) : Subscription
126141 subscribe ( next : ( value : T ) => void , error : null | undefined , complete : ( res : C ) => void ) : Subscription
127142 subscribe (
128- observerOrNext ?: NextObserver < T , E , C > | ( ( value : T ) => void ) | null ,
143+ observerOrNext ?: PartialObserver < T , E , C > | ( ( value : T ) => void ) | null ,
129144 error ?: ( ( err : E ) => void ) | null ,
130145 complete ?: ( ( res : C ) => void ) | null
131146 ) : Subscription {
0 commit comments