Which @angular/* package(s) are the source of the bug?
core
Is this a regression?
No
Description
The hasValue() method of the ResourceRef interface doesn't seem to successfully narrow down the type of its value signal, which is unfortunate since this seems to be hasValue()'s only use.
@Component({
// ...
template: `
@if (res.hasValue()) {
{{ someMethod(res.value()) }} <!-- error -->
}
`,
})
export class AppComponent {
res: ResourceRef<string>; // created with resource method from @angular/core
someMethod(str: string) { }
}
In this case, res.value(), despite being inside a context where hasValue() is true, is still considered to have type string | undefined.
Please provide a link to a minimal reproduction of the bug
https://stackblitz.com/edit/stackblitz-starters-wh7weqvh?file=src%2Fapp%2Fapp.component.ts
Please provide the exception or error you saw
Type 'undefined' is not assignable to type 'string'. [plugin angular-compiler]
src/app/app.component.ts:7:24:
7 │ {{ someMethod(res.value()) }}
Please provide the environment you discovered this bug in (run ng version)
Angular CLI: 19.1.1
Node: 22.13.0
Package Manager: npm 11.0.0
OS: win32 x64
Angular: 19.1.1
... animations, cli, common, compiler, compiler-cli, core, forms
... localize, platform-browser, platform-browser-dynamic, router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1901.1
@angular-devkit/build-angular 19.1.1
@angular-devkit/core 19.1.1
@angular-devkit/schematics 19.1.1
@angular/cdk 19.1.0
@angular/material 19.1.0
@schematics/angular 19.1.1
rxjs 7.8.1
typescript 5.5.4
zone.js 0.15.0
Anything else?
This kind of feels like a TypeScript problem and not an Angular problem
Which @angular/* package(s) are the source of the bug?
core
Is this a regression?
No
Description
The
hasValue()method of theResourceRefinterface doesn't seem to successfully narrow down the type of itsvaluesignal, which is unfortunate since this seems to behasValue()'s only use.In this case,
res.value(), despite being inside a context wherehasValue()is true, is still considered to have typestring | undefined.Please provide a link to a minimal reproduction of the bug
https://stackblitz.com/edit/stackblitz-starters-wh7weqvh?file=src%2Fapp%2Fapp.component.ts
Please provide the exception or error you saw
Please provide the environment you discovered this bug in (run
ng version)Anything else?
This kind of feels like a TypeScript problem and not an Angular problem