|
1 |
| -import { ErrorState, LoadedState, LoadingState } from './model'; |
| 1 | +import { |
| 2 | + ErrorState, |
| 3 | + ErrorStateWithValue, |
| 4 | + LoadedState, |
| 5 | + LoadingState, |
| 6 | + LoadingStateWithValue, |
| 7 | +} from './model'; |
2 | 8 | import { HttpErrorResponse } from '@angular/common/http';
|
3 | 9 |
|
4 | 10 | /**
|
5 | 11 | * Returns a new LoadingState instance with an optional last-known value.
|
6 | 12 | *
|
7 | 13 | * @param value may be provided to indicate the previously-loaded, or last-known, state
|
8 | 14 | */
|
9 |
| -// eslint-disable-next-line @typescript-eslint/no-explicit-any |
10 |
| -export const loadingState = <T = any>(value?: T): LoadingState<T> => ({ |
11 |
| - isLoading: true, |
12 |
| - value, |
13 |
| - error: undefined, |
14 |
| -}); |
| 15 | +export function loadingState<T>(value: T): LoadingStateWithValue<T>; |
| 16 | +export function loadingState<T = never>(): LoadingState<T>; |
| 17 | +export function loadingState<T = never>(value?: T): LoadingState<T> { |
| 18 | + return { |
| 19 | + isLoading: true, |
| 20 | + value, |
| 21 | + error: undefined, |
| 22 | + }; |
| 23 | +} |
15 | 24 |
|
16 | 25 | /**
|
17 | 26 | * Returns a new LoadedState instance, with the optional value as the loaded data.
|
18 | 27 | *
|
19 | 28 | * @param value
|
20 | 29 | */
|
21 |
| -export const loadedState = <T>(value: T): LoadedState<T> => ({ |
22 |
| - isLoading: false, |
23 |
| - error: undefined, |
24 |
| - value, |
25 |
| -}); |
| 30 | +export function loadedState<T>(value: T): LoadedState<T> { |
| 31 | + return { |
| 32 | + isLoading: false, |
| 33 | + error: undefined, |
| 34 | + value, |
| 35 | + }; |
| 36 | +} |
26 | 37 |
|
27 | 38 | /**
|
28 | 39 | * Returns a new ErrorState instance with the given error and optional last-known value.
|
29 | 40 | *
|
30 | 41 | * @param error
|
31 | 42 | * @param value may be provided to indicate the previously-loaded, or last-known, state
|
32 | 43 | */
|
33 |
| -// eslint-disable-next-line @typescript-eslint/no-explicit-any |
34 |
| -export const errorState = <T = any>( |
| 44 | +export function errorState<T>( |
| 45 | + error: HttpErrorResponse | Error, |
| 46 | + value: T |
| 47 | +): ErrorStateWithValue<T>; |
| 48 | +export function errorState<T = never>( |
| 49 | + error: HttpErrorResponse | Error |
| 50 | +): ErrorState<T>; |
| 51 | +export function errorState<T = never>( |
35 | 52 | error: HttpErrorResponse | Error,
|
36 | 53 | value?: T
|
37 |
| -): ErrorState<T> => ({ |
38 |
| - isLoading: false, |
39 |
| - error, |
40 |
| - value, |
41 |
| -}); |
| 54 | +): ErrorState<T> { |
| 55 | + return { |
| 56 | + isLoading: false, |
| 57 | + error, |
| 58 | + value, |
| 59 | + }; |
| 60 | +} |
0 commit comments