@@ -14,6 +14,20 @@ export interface NextObserver<T, E, C> {
14
14
complete ?: ( res : C ) => void
15
15
}
16
16
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
+
17
31
export interface IUnsubscribable {
18
32
/** 取消 observer 的订阅 */
19
33
unsubscribe ( ) : void
@@ -27,10 +41,11 @@ export interface ISubscriptionLike extends IUnsubscribable {
27
41
export type TeardownLogic = ( ) => void
28
42
29
43
export 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
34
49
}
35
50
36
51
/** 表示可清理的资源,比如 Observable 的执行 */
@@ -68,7 +83,7 @@ export class Subscriber<T, E, C> extends Subscription implements IObserver<T, E,
68
83
protected destination : Partial < IObserver < T , E , C > >
69
84
70
85
constructor (
71
- observerOrNext ?: NextObserver < T , E , C > | ( ( value : T ) => void ) | null ,
86
+ observerOrNext ?: PartialObserver < T , E , C > | ( ( value : T ) => void ) | null ,
72
87
error ?: ( ( err : E ) => void ) | null ,
73
88
complete ?: ( ( res : C ) => void ) | null
74
89
) {
@@ -120,12 +135,12 @@ export class Observable<T, E, C> implements ISubscribable<T, E, C> {
120
135
121
136
constructor ( private _subscribe : ( subscriber : Subscriber < T , E , C > ) => TeardownLogic ) { }
122
137
123
- subscribe ( observer : NextObserver < T , E , C > ) : Subscription
138
+ subscribe ( observer : PartialObserver < T , E , C > ) : Subscription
124
139
subscribe ( next : null | undefined , error : null | undefined , complete : ( res : C ) => void ) : Subscription
125
140
subscribe ( next : null | undefined , error : ( error : E ) => void , complete ?: ( res : C ) => void ) : Subscription
126
141
subscribe ( next : ( value : T ) => void , error : null | undefined , complete : ( res : C ) => void ) : Subscription
127
142
subscribe (
128
- observerOrNext ?: NextObserver < T , E , C > | ( ( value : T ) => void ) | null ,
143
+ observerOrNext ?: PartialObserver < T , E , C > | ( ( value : T ) => void ) | null ,
129
144
error ?: ( ( err : E ) => void ) | null ,
130
145
complete ?: ( ( res : C ) => void ) | null
131
146
) : Subscription {
0 commit comments