@@ -5,6 +5,7 @@ import type {
5
5
Denormalize ,
6
6
Queryable ,
7
7
SchemaArgs ,
8
+ NI ,
8
9
} from '@data-client/normalizr' ;
9
10
import {
10
11
ExpiryStatus ,
@@ -154,7 +155,7 @@ export default class Controller<
154
155
args [ 0 ] !== null ?
155
156
this . dispatch (
156
157
createInvalidate ( endpoint , {
157
- args : args as readonly [ ... Parameters < E > ] ,
158
+ args : args as Parameters < E > ,
158
159
} ) ,
159
160
)
160
161
: Promise . resolve ( ) ;
@@ -314,17 +315,28 @@ export default class Controller<
314
315
* Gets the error, if any, for a given endpoint. Returns undefined for no errors.
315
316
* @see https://dataclient.io/docs/api/Controller#getError
316
317
*/
317
- getError = <
318
- E extends Pick < EndpointInterface , 'key' > ,
319
- Args extends readonly [ ...Parameters < E [ 'key' ] > ] | readonly [ null ] ,
320
- > (
318
+ getError < E extends EndpointInterface > (
319
+ endpoint : E ,
320
+ ...rest :
321
+ | readonly [ null , State < unknown > ]
322
+ | readonly [ ...Parameters < E > , State < unknown > ]
323
+ ) : ErrorTypes | undefined ;
324
+
325
+ getError < E extends Pick < EndpointInterface , 'key' > > (
321
326
endpoint : E ,
322
- ...rest : [ ...Args , State < unknown > ]
323
- ) : ErrorTypes | undefined => {
327
+ ...rest :
328
+ | readonly [ null , State < unknown > ]
329
+ | readonly [ ...Parameters < E [ 'key' ] > , State < unknown > ]
330
+ ) : ErrorTypes | undefined ;
331
+
332
+ getError (
333
+ endpoint : EndpointInterface ,
334
+ ...rest : readonly [ ...unknown [ ] , State < unknown > ]
335
+ ) : ErrorTypes | undefined {
324
336
if ( rest [ 0 ] === null ) return ;
325
337
const state = rest [ rest . length - 1 ] as State < unknown > ;
326
338
// this is typescript generics breaking
327
- const args : any = rest . slice ( 0 , rest . length - 1 ) as Parameters < E [ 'key' ] > ;
339
+ const args : any = rest . slice ( 0 , rest . length - 1 ) ;
328
340
const key = endpoint . key ( ...args ) ;
329
341
330
342
const meta = selectMeta ( state , key ) ;
@@ -333,24 +345,17 @@ export default class Controller<
333
345
if ( error !== undefined && meta ?. errorPolicy === 'soft' ) return ;
334
346
335
347
return meta ?. error as any ;
336
- } ;
348
+ }
337
349
338
350
/**
339
351
* Gets the (globally referentially stable) response for a given endpoint/args pair from state given.
340
352
* @see https://dataclient.io/docs/api/Controller#getResponse
341
353
*/
342
354
getResponse < E extends EndpointInterface > (
343
355
endpoint : E ,
344
- ...rest : readonly [ null , State < unknown > ]
345
- ) : {
346
- data : DenormalizeNullable < E [ 'schema' ] > ;
347
- expiryStatus : ExpiryStatus ;
348
- expiresAt : number ;
349
- } ;
350
-
351
- getResponse < E extends EndpointInterface > (
352
- endpoint : E ,
353
- ...rest : readonly [ ...Parameters < E > , State < unknown > ]
356
+ ...rest :
357
+ | readonly [ null , State < unknown > ]
358
+ | readonly [ ...Parameters < E > , State < unknown > ]
354
359
) : {
355
360
data : DenormalizeNullable < E [ 'schema' ] > ;
356
361
expiryStatus : ExpiryStatus ;
@@ -613,15 +618,22 @@ class Snapshot<T = unknown> implements SnapshotInterface {
613
618
}
614
619
615
620
/** @see https://dataclient.io/docs/api/Snapshot#getError */
616
- getError = <
617
- E extends Pick < EndpointInterface , 'key' > ,
618
- Args extends readonly [ ...Parameters < E [ 'key' ] > ] ,
619
- > (
621
+ getError < E extends EndpointInterface > (
622
+ endpoint : E ,
623
+ ...args : readonly [ ...Parameters < E > ] | readonly [ null ]
624
+ ) : ErrorTypes | undefined ;
625
+
626
+ getError < E extends Pick < EndpointInterface , 'key' > > (
620
627
endpoint : E ,
621
- ...args : Args
622
- ) : ErrorTypes | undefined => {
628
+ ...args : readonly [ ...Parameters < E [ 'key' ] > ] | readonly [ null ]
629
+ ) : ErrorTypes | undefined ;
630
+
631
+ getError < E extends Pick < EndpointInterface , 'key' > > (
632
+ endpoint : E ,
633
+ ...args : readonly [ ...Parameters < E [ 'key' ] > ] | readonly [ null ]
634
+ ) : ErrorTypes | undefined {
623
635
return this . controller . getError ( endpoint , ...args , this . state ) ;
624
- } ;
636
+ }
625
637
626
638
/**
627
639
* Retrieved memoized value for any Querable schema
0 commit comments