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

Time:03-12

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 one rror: (error: any) => void;
let onCompleted: () => void;

CodePudding user response:

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.

CodePudding user response:

Use these types from RX:

import { Observer } from 'rx';

let onNext: Observer['onNext'];
let one rror: Observer['onError'];
let onCompleted: Observer['onCompleted'];
  • Related