Title: Feature Request: Strong error typing on `Resource` and `HttpResource` signatures · Issue #63070 · angular/angular · GitHub
Open Graph Title: Feature Request: Strong error typing on `Resource` and `HttpResource` signatures · Issue #63070 · angular/angular
X Title: Feature Request: Strong error typing on `Resource` and `HttpResource` signatures · Issue #63070 · angular/angular
Description: Which @angular/* package(s) are relevant/related to the feature request? core, common Description I'd like to suggest a change to resources before they get stabilized. This suggestion is heavily inspired by Rust's Result
Open Graph Description: Which @angular/* package(s) are relevant/related to the feature request? core, common Description I'd like to suggest a change to resources before they get stabilized. This suggestion is heavily in...
X Description: Which @angular/* package(s) are relevant/related to the feature request? core, common Description I'd like to suggest a change to resources before they get stabilized. This suggestion is heavil...
Opengraph URL: https://github.com/angular/angular/issues/63070
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Feature Request: Strong error typing on `Resource` and `HttpResource` signatures","articleBody":"### Which @angular/* package(s) are relevant/related to the feature request?\n\ncore, common\n\n### Description\n\nI'd like to suggest a change to resources before they get stabilized. This suggestion is heavily inspired by Rust's `Result\u003cT, E>` type and a little bit by the libraries [neverthrow](https://github.com/supermacro/neverthrow) and [effect](https://github.com/Effect-TS/effect). The idea is to make errors not be second-class citizens, make them become just another value that is there when an error happened.\n\nCurrently, errors in resources are typed to just be instances of `Error`. As a result, when you use an error in a template or just simply in a component, you have to do dirty tricks if you want to work in a type-safe way with errors. As a result, error handling often becomes more cumbersome and is more likely to be neglected.\n\nWe use resources extensively since their introduction and the ergonomics are great when it comes to the happy path. However, in our application, error handling is often more complex than the success case. There are often many many more things to do when errors occur.\n\nI realise that these suggestions are opinionated and go against what we've been used to from RXJS and Promise APIs, but there have been other libraries gaining popularity that also do this. I do also realise that TypeScript doesn't really help (typing when throwing isn't type checked, etc.), but this would be opt-in anyway, so I don't see how it would be harmful.\n\n### Proposed solution\n\n## Feature request 0: `Resource\u003cT, E extends Error = Error>`\nThis suggestion is sort of a pre-requesit to other suggestions. \n\nThis first suggestion is to add a second optional generic type to resources as well as all their implementations and a new method `hasError()` that works similarly to `hasValue()`.\n\n```typescript\ninterface Resource\u003cT, E extends Error = Error> {\n...\nreadonly error: Signal\u003cE | undefined>;\nhasError(): this is Resource\u003cT, Exclude\u003cE, undefined>>;\n}\n```\n\n## Feature request 1: `Resource\u003cT, E>`\nI personally fail to see the point of requring errors to be instances of `Error`, especially in the context of strong error typing. \nAs an example Rust's `Result\u003cT, E>` doesn't enforce any specific restrictions on E, which makes it much more versatile.\nCurrently, if you throw an error that's not an instance of Error, it gets encapsulated into one. If one might argue that promises don't have error types in their signature, they do allow you to throw with anyhing, not just Errors.\n\n## Feature request 2: `setError(error: E)` and `update(updater: (value: E) => E): void;` on `WritableResource\u003cT, E>`\n## Feature request 3: `setError(error: E)` and `update(updater: (value: E) => E): void;` on `WritableResource\u003cT, E>`\n## Feature request 4: Add `parseError()` to `HttpResourceOptions`.\nThis would allow to be able to shape errors that one would get from an API. This would also have the advantage of being able to enforce type safety on the return error values.\n\n### Alternatives considered\n\nMake custom wrappers around resource APIs in userland that do this instead, but this would make things complicated.","author":{"url":"https://github.com/wartab","@type":"Person","name":"wartab"},"datePublished":"2025-08-09T14:25:13Z","url":"https://github.com/angular/angular/issues/63070"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:19f8e1ab-f709-9957-8d02-4f3c325efd8f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B6EA:363D8E:2E61CD1:3AD51C6:6B01A5DC |
| html-safe-nonce | e7d890b0ce13f151dcf915a530842b8fef14afb6a6bb90d23c833f69462da6f6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNkVBOjM2M0Q4RToyRTYxQ0QxOjNBRDUxQzY6NkIwMUE1REMiLCJ2aXNpdG9yX2lkIjoiNzk0MDg2MzU5NjgzMjA3MzE4MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | c8cb46172fdeba11c367fa8f2ba5eb4bdf149f62df7282e267fa8f275eeda1ce |
| hovercard-subject-tag | issue:3306426083 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/63070/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1bae0004f6fc4248761dfab720c8111b5a188320021f39da42a371c6bd299365/angular/angular/issues/63070 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1bae0004f6fc4248761dfab720c8111b5a188320021f39da42a371c6bd299365/angular/angular/issues/63070 |
| og:image:alt | Which @angular/* package(s) are relevant/related to the feature request? core, common Description I'd like to suggest a change to resources before they get stabilized. This suggestion is heavily in... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | wartab |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width