@@ -288,8 +288,9 @@ describe('type tests', () => {
288
288
} ,
289
289
} )
290
290
291
- const counter1 : number = store . getState ( ) . counter1
292
- const counter2 : number = store . getState ( ) . counter2
291
+ expectTypeOf ( store . getState ( ) . counter1 ) . toBeNumber ( )
292
+
293
+ expectTypeOf ( store . getState ( ) . counter2 ) . toBeNumber ( )
293
294
} )
294
295
295
296
test ( 'empty preloaded state' , ( ) => {
@@ -301,8 +302,9 @@ describe('type tests', () => {
301
302
preloadedState : { } ,
302
303
} )
303
304
304
- const counter1 : number = store . getState ( ) . counter1
305
- const counter2 : number = store . getState ( ) . counter2
305
+ expectTypeOf ( store . getState ( ) . counter1 ) . toBeNumber ( )
306
+
307
+ expectTypeOf ( store . getState ( ) . counter2 ) . toBeNumber ( )
306
308
} )
307
309
308
310
test ( 'excess properties in preloaded state' , ( ) => {
@@ -318,8 +320,9 @@ describe('type tests', () => {
318
320
} ,
319
321
} )
320
322
321
- const counter1 : number = store . getState ( ) . counter1
322
- const counter2 : number = store . getState ( ) . counter2
323
+ expectTypeOf ( store . getState ( ) . counter1 ) . toBeNumber ( )
324
+
325
+ expectTypeOf ( store . getState ( ) . counter2 ) . toBeNumber ( )
323
326
} )
324
327
325
328
test ( 'mismatching properties in preloaded state' , ( ) => {
@@ -334,8 +337,9 @@ describe('type tests', () => {
334
337
} ,
335
338
} )
336
339
337
- const counter1 : number = store . getState ( ) . counter1
338
- const counter2 : number = store . getState ( ) . counter2
340
+ expectTypeOf ( store . getState ( ) . counter1 ) . toBeNumber ( )
341
+
342
+ expectTypeOf ( store . getState ( ) . counter2 ) . toBeNumber ( )
339
343
} )
340
344
341
345
test ( 'string preloaded state when expecting object' , ( ) => {
@@ -348,8 +352,9 @@ describe('type tests', () => {
348
352
preloadedState : 'test' ,
349
353
} )
350
354
351
- const counter1 : number = store . getState ( ) . counter1
352
- const counter2 : number = store . getState ( ) . counter2
355
+ expectTypeOf ( store . getState ( ) . counter1 ) . toBeNumber ( )
356
+
357
+ expectTypeOf ( store . getState ( ) . counter2 ) . toBeNumber ( )
353
358
} )
354
359
355
360
test ( 'nested combineReducers allows partial' , ( ) => {
@@ -371,10 +376,13 @@ describe('type tests', () => {
371
376
} ,
372
377
} )
373
378
374
- const group1counter1 : number = store . getState ( ) . group1 . counter1
375
- const group1counter2 : number = store . getState ( ) . group1 . counter2
376
- const group2counter1 : number = store . getState ( ) . group2 . counter1
377
- const group2counter2 : number = store . getState ( ) . group2 . counter2
379
+ expectTypeOf ( store . getState ( ) . group1 . counter1 ) . toBeNumber ( )
380
+
381
+ expectTypeOf ( store . getState ( ) . group1 . counter2 ) . toBeNumber ( )
382
+
383
+ expectTypeOf ( store . getState ( ) . group2 . counter1 ) . toBeNumber ( )
384
+
385
+ expectTypeOf ( store . getState ( ) . group2 . counter2 ) . toBeNumber ( )
378
386
} )
379
387
380
388
test ( 'non-nested combineReducers does not allow partial' , ( ) => {
@@ -401,10 +409,13 @@ describe('type tests', () => {
401
409
} ,
402
410
} )
403
411
404
- const group1counter1 : number = store . getState ( ) . group1 . counter1
405
- const group1counter2 : number = store . getState ( ) . group1 . counter2
406
- const group2counter1 : number = store . getState ( ) . group2 . counter1
407
- const group2counter2 : number = store . getState ( ) . group2 . counter2
412
+ expectTypeOf ( store . getState ( ) . group1 . counter1 ) . toBeNumber ( )
413
+
414
+ expectTypeOf ( store . getState ( ) . group1 . counter2 ) . toBeNumber ( )
415
+
416
+ expectTypeOf ( store . getState ( ) . group2 . counter1 ) . toBeNumber ( )
417
+
418
+ expectTypeOf ( store . getState ( ) . group2 . counter2 ) . toBeNumber ( )
408
419
} )
409
420
} )
410
421
@@ -416,7 +427,7 @@ describe('type tests', () => {
416
427
}
417
428
418
429
type StateB = string
419
- function thunkB ( ) {
430
+ const thunkB = ( ) => {
420
431
return ( dispatch : Dispatch , getState : ( ) => StateB ) => { }
421
432
}
422
433
@@ -518,9 +529,10 @@ describe('type tests', () => {
518
529
middleware : ( ) =>
519
530
new Tuple ( 0 as unknown as Middleware < ( a : StateA ) => boolean , StateA > ) ,
520
531
} )
521
- const result : boolean = store . dispatch ( 5 )
522
- // @ts -expect-error
523
- const result2 : string = store . dispatch ( 5 )
532
+
533
+ expectTypeOf ( store . dispatch ( 5 ) ) . toBeBoolean ( )
534
+
535
+ expectTypeOf ( store . dispatch ( 5 ) ) . not . toBeString ( )
524
536
} )
525
537
526
538
test ( 'multiple custom middleware' , ( ) => {
@@ -531,14 +543,17 @@ describe('type tests', () => {
531
543
ThunkMiddleware < StateA > ,
532
544
]
533
545
>
546
+
534
547
const store = configureStore ( {
535
548
reducer : reducerA ,
536
549
middleware : ( ) => middleware ,
537
550
} )
538
551
539
- const result : 'A' = store . dispatch ( 'a' )
540
- const result2 : 'B' = store . dispatch ( 'b' )
541
- const result3 : Promise < 'A' > = store . dispatch ( thunkA ( ) )
552
+ expectTypeOf ( store . dispatch ( 'a' ) ) . toEqualTypeOf < 'A' > ( )
553
+
554
+ expectTypeOf ( store . dispatch ( 'b' ) ) . toEqualTypeOf < 'B' > ( )
555
+
556
+ expectTypeOf ( store . dispatch ( thunkA ( ) ) ) . toEqualTypeOf < Promise < 'A' > > ( )
542
557
} )
543
558
544
559
test ( 'Accepts thunk with `unknown`, `undefined` or `null` ThunkAction extraArgument per default' , ( ) => {
@@ -587,10 +602,11 @@ describe('type tests', () => {
587
602
> ) ,
588
603
} )
589
604
590
- const result1 : 'A' = store . dispatch ( 'a' )
591
- const result2 : Promise < 'A' > = store . dispatch ( thunkA ( ) )
592
- // @ts -expect-error
593
- store . dispatch ( thunkB ( ) )
605
+ expectTypeOf ( store . dispatch ( 'a' ) ) . toEqualTypeOf < 'A' > ( )
606
+
607
+ expectTypeOf ( store . dispatch ( thunkA ( ) ) ) . toEqualTypeOf < Promise < 'A' > > ( )
608
+
609
+ expectTypeOf ( store . dispatch ) . parameter ( 0 ) . not . toMatchTypeOf ( thunkB ( ) )
594
610
} )
595
611
596
612
test ( 'custom middleware and getDefaultMiddleware, using prepend' , ( ) => {
@@ -611,10 +627,12 @@ describe('type tests', () => {
611
627
return concatenated
612
628
} ,
613
629
} )
614
- const result1 : 'A' = store . dispatch ( 'a' )
615
- const result2 : Promise < 'A' > = store . dispatch ( thunkA ( ) )
616
- // @ts -expect-error
617
- store . dispatch ( thunkB ( ) )
630
+
631
+ expectTypeOf ( store . dispatch ( 'a' ) ) . toEqualTypeOf < 'A' > ( )
632
+
633
+ expectTypeOf ( store . dispatch ( thunkA ( ) ) ) . toEqualTypeOf < Promise < 'A' > > ( )
634
+
635
+ expectTypeOf ( store . dispatch ) . parameter ( 0 ) . not . toMatchTypeOf ( thunkB ( ) )
618
636
} )
619
637
620
638
test ( 'custom middleware and getDefaultMiddleware, using concat' , ( ) => {
@@ -635,10 +653,12 @@ describe('type tests', () => {
635
653
return concatenated
636
654
} ,
637
655
} )
638
- const result1 : 'A' = store . dispatch ( 'a' )
639
- const result2 : Promise < 'A' > = store . dispatch ( thunkA ( ) )
640
- // @ts -expect-error
641
- store . dispatch ( thunkB ( ) )
656
+
657
+ expectTypeOf ( store . dispatch ( 'a' ) ) . toEqualTypeOf < 'A' > ( )
658
+
659
+ expectTypeOf ( store . dispatch ( thunkA ( ) ) ) . toEqualTypeOf < Promise < 'A' > > ( )
660
+
661
+ expectTypeOf ( store . dispatch ) . parameter ( 0 ) . not . toMatchTypeOf ( thunkB ( ) )
642
662
} )
643
663
644
664
test ( 'middlewareBuilder notation, getDefaultMiddleware (unconfigured)' , ( ) => {
@@ -650,29 +670,36 @@ describe('type tests', () => {
650
670
StateA
651
671
> ) ,
652
672
} )
653
- const result1 : 'A' = store . dispatch ( 'a' )
654
- const result2 : Promise < 'A' > = store . dispatch ( thunkA ( ) )
655
- // @ts -expect-error
656
- store . dispatch ( thunkB ( ) )
673
+
674
+ expectTypeOf ( store . dispatch ( 'a' ) ) . toEqualTypeOf < 'A' > ( )
675
+
676
+ expectTypeOf ( store . dispatch ( thunkA ( ) ) ) . toEqualTypeOf < Promise < 'A' > > ( )
677
+
678
+ expectTypeOf ( store . dispatch ) . parameter ( 0 ) . not . toMatchTypeOf ( thunkB ( ) )
657
679
} )
658
680
659
681
test ( 'middlewareBuilder notation, getDefaultMiddleware, concat & prepend' , ( ) => {
660
682
const otherMiddleware : Middleware < ( a : 'a' ) => 'A' , StateA > =
661
683
_anyMiddleware
684
+
662
685
const otherMiddleware2 : Middleware < ( a : 'b' ) => 'B' , StateA > =
663
686
_anyMiddleware
687
+
664
688
const store = configureStore ( {
665
689
reducer : reducerA ,
666
690
middleware : ( getDefaultMiddleware ) =>
667
691
getDefaultMiddleware ( )
668
692
. concat ( otherMiddleware )
669
693
. prepend ( otherMiddleware2 ) ,
670
694
} )
671
- const result1 : 'A' = store . dispatch ( 'a' )
672
- const result2 : Promise < 'A' > = store . dispatch ( thunkA ( ) )
673
- const result3 : 'B' = store . dispatch ( 'b' )
674
- // @ts -expect-error
675
- store . dispatch ( thunkB ( ) )
695
+
696
+ expectTypeOf ( store . dispatch ( 'a' ) ) . toEqualTypeOf < 'A' > ( )
697
+
698
+ expectTypeOf ( store . dispatch ( thunkA ( ) ) ) . toEqualTypeOf < Promise < 'A' > > ( )
699
+
700
+ expectTypeOf ( store . dispatch ( 'b' ) ) . toEqualTypeOf < 'B' > ( )
701
+
702
+ expectTypeOf ( store . dispatch ) . parameter ( 0 ) . not . toMatchTypeOf ( thunkB ( ) )
676
703
} )
677
704
678
705
test ( 'middlewareBuilder notation, getDefaultMiddleware (thunk: false)' , ( ) => {
@@ -683,9 +710,10 @@ describe('type tests', () => {
683
710
( ( ) => { } ) as any as Middleware < ( a : 'a' ) => 'A' , StateA > ,
684
711
) ,
685
712
} )
686
- const result1 : 'A' = store . dispatch ( 'a' )
687
- // @ts -expect-error
688
- store . dispatch ( thunkA ( ) )
713
+
714
+ expectTypeOf ( store . dispatch ( 'a' ) ) . toEqualTypeOf < 'A' > ( )
715
+
716
+ expectTypeOf ( store . dispatch ) . parameter ( 0 ) . not . toMatchTypeOf ( thunkA ( ) )
689
717
} )
690
718
691
719
test ( "badly typed middleware won't make `dispatch` `any`" , ( ) => {
0 commit comments