Reputation: 1699
I recently came across the following function declaration
subscribe(observerOrNext?: PartialObserver<T> | ((value: T) => void), error?: (error: any) => void, complete?: () => void): Subscription;
I understand that '?' means optional , but what does the rest mean, especially the
: PartialObserver<T> | ((value: T) => void)
part?
Upvotes: 1
Views: 57
Reputation: 23220
I understand that '?' means optional , but what does the rest mean, especially the :
PartialObserver<T> | ((value: T) => void)
part?
The char '|' is known as Union Type and is used here to tell that the observerOrNext
parameter can be one of the foolowing type:
PartialObserver<T>
void
and accept a parameter value
of type T
.The TypeScript documentation for Advanced Types explains in a better way when to use Union Type.
Upvotes: 1