Which @angular/* package(s) are relevant/related to the feature request?
core
Description
Enums in TS are not great. Even though there are use-cases where they are appropriate, most of the time string literals do the job better. I believe ResourceStatus should be a string literal.
Keeping ResourceStatus as enum will result in increased boilerplate without any added benefits:
Example using enum:
import { ResourceStatus } from '@angular/core'; // this import could be removed with string literals
@Component({
template: `
<-- this could be simply comparing to string literal without any lose of strict type checking --/>
@if (countriesResource.status() === status.Resolved) {
...
}
`,
})
export class AppComponent {
readonly #http = inject(HttpClient);
status = ResourceStatus; // // this property could be removed with string literals
countriesResource = rxResource({
loader: () =>
this.#http.get<Country[]>('https://restcountries.com/v3.1/all'),
});
}
Example using string literal:
@Component({
template: `
@if (countriesResource.status() === 'resolved') {
...
}
`,
})
export class AppComponent {
readonly #http = inject(HttpClient);
countriesResource = rxResource({
loader: () =>
this.#http.get<Country[]>('https://restcountries.com/v3.1/all'),
});
}
There is already confusion about how to check the value of the status in the template here
Proposed solution
export type ResourceStatus =
| 'idle'
| 'error'
| 'loading'
| 'reloading'
| 'resolved'
| 'local';
Alternatives considered
none
Which @angular/* package(s) are relevant/related to the feature request?
core
Description
Enums in TS are not great. Even though there are use-cases where they are appropriate, most of the time string literals do the job better. I believe
ResourceStatusshould be a string literal.Keeping
ResourceStatusasenumwill result in increased boilerplate without any added benefits:Example using enum:
Example using string literal:
There is already confusion about how to check the value of the status in the template here
Proposed solution
Alternatives considered
none