1

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?

1

1 Answer 1

1

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 observerOrNextparameter can be one of the foolowing type:

  • generic type PartialObserver<T>
  • or a callback function which signature must return nothing e.g. 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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.