Strongly type Observable Error
See original GitHub issueRxJS 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:
- Created 6 years ago
- Reactions:60
- Comments:7 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.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 thenObservable
should be changed too. Until then, rxjs should stay consistent with how TypeScript treats synchronous exceptions andPromise
rejections (including, the error type should only becomeunknown
ifpromise.catch()
changesany
tounknown
).