question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Strongly type Observable Error

See original GitHub issue

RxJS version: rxjs@5.0.3

Code to reproduce: none

Expected behavior: Observable<T,E> should be used for definition where E tell type of error to be expected

Actual behavior: Observable<T> where error is typed as any

Additional information: Typescript 2.3 provide default type for generics using that we can have Observable<T,E=any> for backward compability

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:60
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

20reactions
felixfbeckercommented, Jun 28, 2017

I disagree. TypeScript does not have error types. In Java, thrown error types are part of the interface contract, declared with throws. This does not exist in TypeScript, only the return type is part of the interface contract. The error type could be anything if you call other functions, so you should do runtime type checking, like checking for an error code. Consequently, Promises don’t have an error type, and Observables shouldn’t either.

10reactions
felixfbeckercommented, Jun 13, 2018

Btw, the equivalent issue in TypeScript is https://github.com/Microsoft/TypeScript/issues/13219. If we ever get that issue (declarations for exceptions a function can throw), Promise would be changed to have an error type, and then Observable should be changed too. Until then, rxjs should stay consistent with how TypeScript treats synchronous exceptions and Promise rejections (including, the error type should only become unknown if promise.catch() changes any to unknown).

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript/RxJS - Appropriately handling observable error?
when catching an error emitted by an observable? The program will still throw an UnhandledPromiseRejection: exception.
Read more >
How to Make Type Safe HTTP Requests in Angular | Pluralsight
This guide will show you how you can use custom types together with Angular's HttpClient to create powerfully simple and declarative HTTP ...
Read more >
Error Handling With Observable Sequences | RxJS
The first topic is catching errors as they happen with our streams. In the Reactive Extensions, any error is propogated through the onError...
Read more >
Angular HTTP GET Example using httpclient - TekTutorialsHub
Strongly typed response; String as Response Type. Catching Errors; Transform the ... When the observable completes or an error occurs, we make it...
Read more >
Observable | RxJS API Document - ReactiveX
When the output function is called with arguments, it will return an Observable. If func calls its callback with error parameter present, Observable...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found