@@ -15,9 +15,9 @@ function idLoader<K, C = K>(
1515
1616describe ( "Primary API" , ( ) => {
1717 it ( "builds a really really simple data loader" , async ( ) => {
18- const identityLoader = new DataLoader < number , number > ( async ( keys ) => [
19- ... keys ,
20- ] ) ;
18+ const identityLoader = new DataLoader < number , number > ( ( keys ) =>
19+ Promise . resolve ( [ ... keys ] ) ,
20+ ) ;
2121
2222 const promise1 = identityLoader . load ( 1 ) ;
2323 expect ( promise1 ) . toBeInstanceOf ( Promise ) ;
@@ -27,9 +27,9 @@ describe("Primary API", () => {
2727 } ) ;
2828
2929 it ( "supports loading multiple keys in one call" , async ( ) => {
30- const identityLoader = new DataLoader < number , number > ( async ( keys ) => [
31- ... keys ,
32- ] ) ;
30+ const identityLoader = new DataLoader < number , number > ( ( keys ) =>
31+ Promise . resolve ( [ ... keys ] ) ,
32+ ) ;
3333
3434 const promiseAll = identityLoader . loadMany ( [ 1 , 2 ] ) ;
3535 expect ( promiseAll ) . toBeInstanceOf ( Promise ) ;
@@ -109,7 +109,7 @@ describe("Primary API", () => {
109109
110110 it ( "batches cached requests" , async ( ) => {
111111 const loadCalls : number [ ] [ ] = [ ] ;
112- let resolveBatch = ( ) => {
112+ let resolveBatch : ( ) => void = ( ) => {
113113 // noop
114114 } ;
115115 const identityLoader = new DataLoader < number , number > ( ( keys ) => {
@@ -129,10 +129,10 @@ describe("Primary API", () => {
129129 // Track when each resolves.
130130 let promise1Resolved = false ;
131131 let promise2Resolved = false ;
132- promise1 . then ( ( ) => {
132+ void promise1 . then ( ( ) => {
133133 promise1Resolved = true ;
134134 } ) ;
135- promise2 . then ( ( ) => {
135+ void promise2 . then ( ( ) => {
136136 promise2Resolved = true ;
137137 } ) ;
138138
@@ -158,7 +158,9 @@ describe("Primary API", () => {
158158
159159 it ( "max batch size respects cached results" , async ( ) => {
160160 const loadCalls : number [ ] [ ] = [ ] ;
161- let resolveBatch = ( ) => { } ;
161+ let resolveBatch : ( ) => void = ( ) => {
162+ // noop
163+ } ;
162164 const identityLoader = new DataLoader < number , number > (
163165 ( keys ) => {
164166 loadCalls . push ( [ ...keys ] ) ;
@@ -179,10 +181,10 @@ describe("Primary API", () => {
179181 // Track when each resolves.
180182 let promise1Resolved = false ;
181183 let promise2Resolved = false ;
182- promise1 . then ( ( ) => {
184+ void promise1 . then ( ( ) => {
183185 promise1Resolved = true ;
184186 } ) ;
185- promise2 . then ( ( ) => {
187+ void promise2 . then ( ( ) => {
186188 promise2Resolved = true ;
187189 } ) ;
188190
@@ -424,7 +426,9 @@ describe("Represents Errors", () => {
424426 const evenLoader = new DataLoader < number , number > ( ( keys ) => {
425427 loadCalls . push ( [ ...keys ] ) ;
426428 return Promise . resolve (
427- keys . map ( ( key ) => ( key % 2 === 0 ? key : new Error ( `Odd: ${ key } ` ) ) ) ,
429+ keys . map ( ( key ) =>
430+ key % 2 === 0 ? key : new Error ( `Odd: ${ String ( key ) } ` ) ,
431+ ) ,
428432 ) ;
429433 } ) ;
430434
@@ -448,21 +452,23 @@ describe("Represents Errors", () => {
448452 const evenLoader = new DataLoader < number , number > ( ( keys ) => {
449453 loadCalls . push ( [ ...keys ] ) ;
450454 return Promise . resolve (
451- keys . map ( ( key ) => ( key % 2 === 0 ? key : new Error ( `Odd: ${ key } ` ) ) ) ,
455+ keys . map ( ( key ) =>
456+ key % 2 === 0 ? key : new Error ( `Odd: ${ String ( key ) } ` ) ,
457+ ) ,
452458 ) ;
453459 } ) ;
454460
455461 const promise1 = evenLoader . load ( 1 ) ;
456462 const promise2 = evenLoader . load ( 2 ) ;
457463
458- let caughtError : any ;
464+ let caughtError : unknown ;
459465 try {
460466 await promise1 ;
461467 } catch ( error ) {
462468 caughtError = error ;
463469 }
464470 expect ( caughtError ) . toBeInstanceOf ( Error ) ;
465- expect ( caughtError . message ) . toBe ( "Odd: 1" ) ;
471+ expect ( ( caughtError as Error ) . message ) . toBe ( "Odd: 1" ) ;
466472
467473 expect ( await promise2 ) . toBe ( 2 ) ;
468474
@@ -473,26 +479,28 @@ describe("Represents Errors", () => {
473479 const loadCalls : number [ ] [ ] = [ ] ;
474480 const errorLoader = new DataLoader < number , number > ( ( keys ) => {
475481 loadCalls . push ( [ ...keys ] ) ;
476- return Promise . resolve ( keys . map ( ( key ) => new Error ( `Error: ${ key } ` ) ) ) ;
482+ return Promise . resolve (
483+ keys . map ( ( key ) => new Error ( `Error: ${ String ( key ) } ` ) ) ,
484+ ) ;
477485 } ) ;
478486
479- let caughtErrorA : any ;
487+ let caughtErrorA : unknown ;
480488 try {
481489 await errorLoader . load ( 1 ) ;
482490 } catch ( error ) {
483491 caughtErrorA = error ;
484492 }
485493 expect ( caughtErrorA ) . toBeInstanceOf ( Error ) ;
486- expect ( caughtErrorA . message ) . toBe ( "Error: 1" ) ;
494+ expect ( ( caughtErrorA as Error ) . message ) . toBe ( "Error: 1" ) ;
487495
488- let caughtErrorB : any ;
496+ let caughtErrorB : unknown ;
489497 try {
490498 await errorLoader . load ( 1 ) ;
491499 } catch ( error ) {
492500 caughtErrorB = error ;
493501 }
494502 expect ( caughtErrorB ) . toBeInstanceOf ( Error ) ;
495- expect ( caughtErrorB . message ) . toBe ( "Error: 1" ) ;
503+ expect ( ( caughtErrorB as Error ) . message ) . toBe ( "Error: 1" ) ;
496504
497505 expect ( loadCalls ) . toEqual ( [ [ 1 ] ] ) ;
498506 } ) ;
@@ -505,14 +513,14 @@ describe("Represents Errors", () => {
505513 // Wait a bit.
506514 await new Promise ( ( resolve ) => setTimeout ( resolve , 0 ) ) ;
507515
508- let caughtErrorA : any ;
516+ let caughtErrorA : unknown ;
509517 try {
510518 await identityLoader . load ( 1 ) ;
511519 } catch ( error ) {
512520 caughtErrorA = error ;
513521 }
514522 expect ( caughtErrorA ) . toBeInstanceOf ( Error ) ;
515- expect ( caughtErrorA . message ) . toBe ( "Error: 1" ) ;
523+ expect ( ( caughtErrorA as Error ) . message ) . toBe ( "Error: 1" ) ;
516524
517525 expect ( loadCalls ) . toEqual ( [ ] ) ;
518526 } ) ;
@@ -521,12 +529,14 @@ describe("Represents Errors", () => {
521529 const loadCalls : number [ ] [ ] = [ ] ;
522530 const errorLoader = new DataLoader < number , number > ( ( keys ) => {
523531 loadCalls . push ( [ ...keys ] ) ;
524- return Promise . resolve ( keys . map ( ( key ) => new Error ( `Error: ${ key } ` ) ) ) ;
532+ return Promise . resolve (
533+ keys . map ( ( key ) => new Error ( `Error: ${ String ( key ) } ` ) ) ,
534+ ) ;
525535 } ) ;
526536
527- let caughtErrorA : any ;
537+ let caughtErrorA : unknown ;
528538 try {
529- await errorLoader . load ( 1 ) . catch ( ( error ) => {
539+ await errorLoader . load ( 1 ) . catch ( ( error : unknown ) => {
530540 // Presumably determine if this error is transient, and only clear the
531541 // cache in that case.
532542 errorLoader . clear ( 1 ) ;
@@ -536,11 +546,11 @@ describe("Represents Errors", () => {
536546 caughtErrorA = error ;
537547 }
538548 expect ( caughtErrorA ) . toBeInstanceOf ( Error ) ;
539- expect ( caughtErrorA . message ) . toBe ( "Error: 1" ) ;
549+ expect ( ( caughtErrorA as Error ) . message ) . toBe ( "Error: 1" ) ;
540550
541- let caughtErrorB : any ;
551+ let caughtErrorB : unknown ;
542552 try {
543- await errorLoader . load ( 1 ) . catch ( ( error ) => {
553+ await errorLoader . load ( 1 ) . catch ( ( error : unknown ) => {
544554 // Again, only do this if you can determine the error is transient.
545555 errorLoader . clear ( 1 ) ;
546556 throw error ;
@@ -549,7 +559,7 @@ describe("Represents Errors", () => {
549559 caughtErrorB = error ;
550560 }
551561 expect ( caughtErrorB ) . toBeInstanceOf ( Error ) ;
552- expect ( caughtErrorB . message ) . toBe ( "Error: 1" ) ;
562+ expect ( ( caughtErrorB as Error ) . message ) . toBe ( "Error: 1" ) ;
553563
554564 expect ( loadCalls ) . toEqual ( [ [ 1 ] , [ 1 ] ] ) ;
555565 } ) ;
@@ -564,16 +574,16 @@ describe("Represents Errors", () => {
564574 const promise1 = failLoader . load ( 1 ) ;
565575 const promise2 = failLoader . load ( 2 ) ;
566576
567- let caughtErrorA : any ;
577+ let caughtErrorA : unknown ;
568578 try {
569579 await promise1 ;
570580 } catch ( error ) {
571581 caughtErrorA = error ;
572582 }
573583 expect ( caughtErrorA ) . toBeInstanceOf ( Error ) ;
574- expect ( caughtErrorA . message ) . toBe ( "I am a terrible loader" ) ;
584+ expect ( ( caughtErrorA as Error ) . message ) . toBe ( "I am a terrible loader" ) ;
575585
576- let caughtErrorB : any ;
586+ let caughtErrorB : unknown ;
577587 try {
578588 await promise2 ;
579589 } catch ( error ) {
@@ -587,7 +597,7 @@ describe("Represents Errors", () => {
587597
588598describe ( "Accepts any kind of key" , ( ) => {
589599 it ( "Accepts objects as keys" , async ( ) => {
590- const [ identityLoader , loadCalls ] = idLoader < { } > ( ) ;
600+ const [ identityLoader , loadCalls ] = idLoader < object > ( ) ;
591601
592602 const keyA = { } ;
593603 const keyB = { } ;
@@ -604,8 +614,8 @@ describe("Accepts any kind of key", () => {
604614
605615 expect ( loadCalls ) . toHaveLength ( 1 ) ;
606616 expect ( loadCalls [ 0 ] ) . toHaveLength ( 2 ) ;
607- expect ( loadCalls [ 0 ] ! [ 0 ] ) . toBe ( keyA ) ;
608- expect ( loadCalls [ 0 ] ! [ 1 ] ) . toBe ( keyB ) ;
617+ expect ( loadCalls [ 0 ] ?. [ 0 ] ) . toBe ( keyA ) ;
618+ expect ( loadCalls [ 0 ] ?. [ 1 ] ) . toBe ( keyB ) ;
609619
610620 // Caching
611621
@@ -621,7 +631,7 @@ describe("Accepts any kind of key", () => {
621631
622632 expect ( loadCalls ) . toHaveLength ( 2 ) ;
623633 expect ( loadCalls [ 1 ] ) . toHaveLength ( 1 ) ;
624- expect ( loadCalls [ 1 ] ! [ 0 ] ) . toBe ( keyA ) ;
634+ expect ( loadCalls [ 1 ] ?. [ 0 ] ) . toBe ( keyA ) ;
625635 } ) ;
626636} ) ;
627637
@@ -770,10 +780,10 @@ describe("Accepts options", () => {
770780 } ) ;
771781
772782 describe ( "Accepts object key in custom cacheKey function" , ( ) => {
773- function cacheKey ( key : Record < string , any > ) : string {
783+ function cacheKey ( key : Record < string , unknown > ) : string {
774784 return Object . keys ( key )
775785 . sort ( )
776- . map ( ( k ) => `${ k } :${ key [ k ] } ` )
786+ . map ( ( k ) => `${ k } :${ String ( key [ k ] ) } ` )
777787 . join ( ) ;
778788 }
779789
@@ -847,7 +857,7 @@ describe("Accepts options", () => {
847857
848858 expect ( identityLoadCalls ) . toHaveLength ( 1 ) ;
849859 expect ( identityLoadCalls [ 0 ] ) . toHaveLength ( 1 ) ;
850- expect ( identityLoadCalls [ 0 ] ! [ 0 ] ) . toBe ( keyA ) ;
860+ expect ( identityLoadCalls [ 0 ] ?. [ 0 ] ) . toBe ( keyA ) ;
851861 } ) ;
852862
853863 it ( "Allows priming the cache with an object key" , async ( ) => {
@@ -883,6 +893,7 @@ describe("Accepts options", () => {
883893 this . stash [ String ( key ) ] = value ;
884894 }
885895 delete ( key : K ) {
896+ // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
886897 delete this . stash [ String ( key ) ] ;
887898 }
888899 clear ( ) {
@@ -960,19 +971,21 @@ describe("It allows custom schedulers", () => {
960971 } ;
961972 }
962973
963- const { schedule , dispatch } = createScheduler ( ) ;
974+ const scheduler = createScheduler ( ) ;
964975 const [ identityLoader , loadCalls ] = idLoader < string > ( {
965- batchScheduleFn : schedule ,
976+ batchScheduleFn : ( callback ) => {
977+ scheduler . schedule ( callback ) ;
978+ } ,
966979 } ) ;
967980
968- identityLoader . load ( "A" ) ;
969- identityLoader . load ( "B" ) ;
970- dispatch ( ) ;
971- identityLoader . load ( "A" ) ;
972- identityLoader . load ( "C" ) ;
973- dispatch ( ) ;
981+ void identityLoader . load ( "A" ) ;
982+ void identityLoader . load ( "B" ) ;
983+ scheduler . dispatch ( ) ;
984+ void identityLoader . load ( "A" ) ;
985+ void identityLoader . load ( "C" ) ;
986+ scheduler . dispatch ( ) ;
974987 // Note: never dispatched!
975- identityLoader . load ( "D" ) ;
988+ void identityLoader . load ( "D" ) ;
976989
977990 expect ( loadCalls ) . toEqual ( [ [ "A" , "B" ] , [ "C" ] ] ) ;
978991 } ) ;
@@ -987,15 +1000,15 @@ describe("It is resilient to job queue ordering", () => {
9871000 Promise . resolve ( )
9881001 . then ( ( ) => Promise . resolve ( ) )
9891002 . then ( ( ) => {
990- identityLoader . load ( "B" ) ;
1003+ void identityLoader . load ( "B" ) ;
9911004 return Promise . resolve ( )
9921005 . then ( ( ) => Promise . resolve ( ) )
9931006 . then ( ( ) => {
994- identityLoader . load ( "C" ) ;
1007+ void identityLoader . load ( "C" ) ;
9951008 return Promise . resolve ( )
9961009 . then ( ( ) => Promise . resolve ( ) )
9971010 . then ( ( ) => {
998- identityLoader . load ( "D" ) ;
1011+ void identityLoader . load ( "D" ) ;
9991012 } ) ;
10001013 } ) ;
10011014 } ) ,
0 commit comments