@@ -12,6 +12,7 @@ import {effect, EffectRef} from '../render3/reactivity/effect';
1212import { signal , signalAsReadonlyFn , WritableSignal } from '../render3/reactivity/signal' ;
1313import { untracked } from '../render3/reactivity/untracked' ;
1414import {
15+ PromiseResourceOptions ,
1516 Resource ,
1617 ResourceDependencyError ,
1718 ResourceLoaderParams ,
@@ -26,6 +27,10 @@ import {
2627 type ResourceRef ,
2728 type WritableResource ,
2829} from './api' ;
30+ import {
31+ ResourceOptionsWithOptionalParams ,
32+ ResourceOptionsWithRequiredParams ,
33+ } from './resource_option_types' ;
2934
3035import { assertInInjectionContext } from '../di/contextual' ;
3136import { Injector } from '../di/injector' ;
@@ -35,6 +40,18 @@ import {DestroyRef} from '../linker/destroy_ref';
3540import { PendingTasks } from '../pending_tasks' ;
3641import { linkedSignal } from '../render3/reactivity/linked_signal' ;
3742
43+ type ResourceOptionsWithRequiredLoader < T , R > = (
44+ | Omit < PromiseResourceOptions < T , R > , 'params' >
45+ | Omit < StreamingResourceOptions < T , R > , 'params' >
46+ ) &
47+ ResourceOptionsWithRequiredParams < T , R > ;
48+
49+ type ResourceOptionsWithOptionalLoader < T , R > = (
50+ | Omit < PromiseResourceOptions < T , Exclude < R , undefined > | null > , 'params' >
51+ | Omit < StreamingResourceOptions < T , Exclude < R , undefined > | null > , 'params' >
52+ ) &
53+ ResourceOptionsWithOptionalParams < T , R > ;
54+
3855/**
3956 * Constructs a `Resource` that projects a reactive request to an asynchronous operation defined by
4057 * a loader function, which exposes the result of the loading operation via signals.
@@ -48,7 +65,11 @@ import {linkedSignal} from '../render3/reactivity/linked_signal';
4865 * @experimental 19.0
4966 */
5067export function resource < T , R > (
51- options : ResourceOptions < T , R > & { defaultValue : NoInfer < T > } ,
68+ options : ResourceOptionsWithRequiredLoader < T , R > & { defaultValue : NoInfer < T > } ,
69+ ) : ResourceRef < T > ;
70+
71+ export function resource < T , R = never > (
72+ options : ResourceOptionsWithOptionalLoader < T , R > & { defaultValue : NoInfer < T > } ,
5273) : ResourceRef < T > ;
5374
5475/**
@@ -62,7 +83,12 @@ export function resource<T, R>(
6283 * @experimental 19.0
6384 * @see [Async reactivity with resources](guide/signals/resource)
6485 */
65- export function resource < T , R > ( options : ResourceOptions < T , R > ) : ResourceRef < T | undefined > ;
86+ export function resource < T , R > (
87+ options : ResourceOptionsWithRequiredLoader < T , R > ,
88+ ) : ResourceRef < T | undefined > ;
89+ export function resource < T , R = never > (
90+ options : ResourceOptionsWithOptionalLoader < T , R > ,
91+ ) : ResourceRef < T | undefined > ;
6692export function resource < T , R > ( options : ResourceOptions < T , R > ) : ResourceRef < T | undefined > {
6793 if ( ngDevMode && ! options ?. injector ) {
6894 assertInInjectionContext ( resource ) ;
0 commit comments