'What are the types for the RX JS Observer functions (onNext, onError and onCompleted)?

I've got a wrapper function around an RX Subject. Is there a better way to specify these types?

let onNext: (element: any) => void;
let onError: (error: any) => void;
let onCompleted: () => void;


Solution 1:[1]

You can import types right from rxjs:

import { Observer, NextObserver, CompletionObserver, ErrorObserver } from 'rxjs';

Types XyObserver only require one handler, while Observer all three handlers.

Solution 2:[2]

Use these types from RX:

import { Observer } from 'rx';

let onNext: Observer['onNext'];
let onError: Observer['onError'];
let onCompleted: Observer['onCompleted'];

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 martin
Solution 2 A Jar of Clay