fix(angular): correct the httpResource stability note and keep the hasValue guard - #3828
fix(angular): correct the httpResource stability note and keep the hasValue guard#3828the-ult wants to merge 2 commits into
Conversation
…sValue guard
Every generated resource function carried
`@experimental httpResource is experimental (Angular v19.2+)`.
`httpResource` carries `@experimental 19.2` up to Angular 21 and
`@publicApi 22.0` from Angular 22, so the note is wrong for current
Angular. Orval supports Angular 19.2 and later, so a stability claim
cannot be correct for the whole range. The note now gives the
availability fact only:
@remarks httpResource is available in Angular 19.2 and later.
`toResourceState` also erased a type guard. Angular declares
`hasValue()` on `HttpResourceRef` as a type predicate, and its
documentation tells users to guard `value()` with it, because reading
`value()` in an error state throws. The generated `ResourceState`
declared `hasValue: () => boolean`, so `value()` stayed
`T | undefined` after the guard.
`hasValue` is now a predicate onto a new `ResolvedResourceState<T>`,
which narrows `value` to `Signal<Exclude<T, undefined>>`. `Exclude`
mirrors Angular's own overload and keeps `null`, because a resource
that holds `null` does have a value. Runtime behaviour does not
change, and the shape is still assignable to a `() => boolean`
consumer.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThe change documents ChangesAngular httpResource updates
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Updates the Angular httpResource generator output to reflect current Angular API status and to preserve Angular’s hasValue() type-guard semantics when wrapping an HttpResourceRef into a flattened ResourceState helper.
Changes:
- Replaces the generated
@experimentalJSDoc note with an availability-only@remarksnote for Angular 19.2+. - Introduces
ResolvedResourceState<T>and makesResourceState<T>.hasValue()athis is ...type guard, implemented viatoResourceState(). - Updates Angular-related snapshots and sample generated outputs to match the new emitted types/docs.
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/snapshots/angular/url-encode-parameters-http-resource/endpoints.ts | Snapshot updates for @remarks note + ResolvedResourceState/hasValue guard emission |
| tests/snapshots/angular/issue-3712-http-resource/endpoints.ts | Snapshot updates for @remarks note + ResolvedResourceState/hasValue guard emission |
| tests/snapshots/angular/issue-3705-http-resource/endpoints.ts | Snapshot updates for @remarks note + ResolvedResourceState/hasValue guard emission |
| tests/snapshots/angular/issue-3624/petstore.client.service.ts | Snapshot updates for @remarks note + ResolvedResourceState/hasValue guard emission |
| tests/snapshots/angular/http-resource-zod/endpoints.ts | Snapshot updates for @remarks note + ResolvedResourceState/hasValue guard emission |
| tests/snapshots/angular/http-resource-zod-disabled/endpoints.ts | Snapshot updates for @remarks note + ResolvedResourceState/hasValue guard emission |
| tests/snapshots/angular/http-resource-tags/pets.ts | Snapshot updates for @remarks note + ResolvedResourceState/hasValue guard emission |
| tests/snapshots/angular/http-resource-tags/health.ts | Snapshot updates for @remarks note + ResolvedResourceState/hasValue guard emission |
| tests/snapshots/angular/http-resource-request-extension-multi-content/endpoints.ts | Snapshot updates for @remarks note + ResolvedResourceState/hasValue guard emission |
| tests/snapshots/angular/http-resource-multi-content/endpoints.ts | Snapshot updates for @remarks note + ResolvedResourceState/hasValue guard emission |
| tests/snapshots/angular/http-resource-headers/endpoints.ts | Snapshot updates for @remarks note + ResolvedResourceState/hasValue guard emission |
| tests/snapshots/angular/http-resource-both-tags-split/pets/pets.resource.ts | Snapshot updates for @remarks note + ResolvedResourceState/hasValue guard emission |
| tests/snapshots/angular/http-resource-both-tags-split/health/health.resource.ts | Snapshot updates for @remarks note + ResolvedResourceState/hasValue guard emission |
| samples/angular-app/src/api/http-resource/pets/pets.service.ts | Sample generated output updated to new JSDoc note + state narrowing types |
| samples/angular-app/src/api/http-resource-zod/pets/pets.service.ts | Sample generated output updated to new JSDoc note + state narrowing types |
| samples/angular-app/src/api/http-both/pets/pets.resource.ts | Sample generated output updated to new JSDoc note + state narrowing types |
| samples/angular-app/snapshots/api/http-resource/pets/pets.service.ts | Sample snapshot updated to new JSDoc note + state narrowing types |
| samples/angular-app/snapshots/api/http-resource-zod/pets/pets.service.ts | Sample snapshot updated to new JSDoc note + state narrowing types |
| samples/angular-app/snapshots/api/http-both/pets/pets.resource.ts | Sample snapshot updated to new JSDoc note + state narrowing types |
| packages/angular/src/http-resource.ts | Generator source: emits @remarks note; emits ResolvedResourceState<T> and hasValue() as a type guard |
| packages/angular/src/http-resource.test.ts | Updates the JSDoc annotation assertion for the generated resource header |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
@orval/angular
@orval/axios
@orval/core
@orval/effect
@orval/fetch
@orval/hono
@orval/mcp
@orval/mock
orval
@orval/query
@orval/solid-start
@orval/swr
@orval/zod
commit: |
the-ult
left a comment
There was a problem hiding this comment.
and fix the issues. Apply your recommended fixes
the-ult
left a comment
There was a problem hiding this comment.
fix the issues. Apply your recommended fixes
What
Two problems in the generated Angular
httpResourceoutput.1. The stability note is wrong. Every generated resource function carries:
httpResourceis annotated@experimental 19.2in@angular/commonup to Angular 21, and@publicApi 22.0from Angular 22. The note is therefore wrong for current Angular.2.
toResourceStateerases a type guard. Angular declareshasValue()onHttpResourceRefas a type predicate, and its documentation tells users to guardvalue()with it, because readingvalue()in an error state throws. The generatedResourceStateflattened it:So
value()stayedPet | undefinedafter the guard, and the documented pattern did not typecheck.Fix
Orval supports Angular 19.2 and later, so no stability claim is correct for the whole range. The note now gives the availability fact only:
hasValueis now a predicate onto a new exported interface:Exclude<T, undefined>mirrors Angular's own overload rather thanNonNullable, because a resource that holdsnulldoes have a value.Two simpler shapes were tried first and both fail.
this is ResourceState<NonNullable<T>>leavesvalueasSignal<T | undefined>. An intersection that overridesvaluealso fails, because intersected call signatures behave as overloads and the first declared one wins. A sub-interface is what actually narrows.Runtime behaviour does not change. The result is still assignable to a
() => booleanconsumer, so structural users such as ngrx-toolkitwithResourcekeep working.User-visible changes
Generated resource files carry the corrected note, and
hasValue()now narrowsvalue():21 generated fixture and sample files change: 63 note replacements, and 19 files gain the
ResolvedResourceStatedeclaration. Two of the 21 are tag-split files that do not emit the state utilities.Tests
packages/angular/src/http-resource.test.tscovers the emitted note and the declaration. The narrowing was verified against real generated output under Angular'sstricttsconfig withEqual<>assertions:Pet | undefinedbefore the guard,Petafter, andnullpreserved.Verification
build:release,typecheck,lint,format:check,test,test:snapshots— all green. The roottypecheckcoverspackages/*, so the generated output was typechecked separately throughsamples/angular-app/tsconfig.app.json.🤖 Generated with Claude Code
Summary by CodeRabbit
hasValue().httpResourcedocumentation to indicate availability in Angular 19.2 and later.