@@ -2,7 +2,9 @@ import { fakeAsync, TestBed, tick } from '@angular/core/testing';
22import { patchState , signalStore , withState } from '@ngrx/signals' ;
33import { delay , Observable , of , Subject , switchMap , throwError } from 'rxjs' ;
44import { concatOp , exhaustOp , mergeOp , switchOp } from './flattening-operator' ;
5+ import { Mutation , MutationResult } from './mutation/mutation' ;
56import { rxMutation } from './mutation/rx-mutation' ;
7+ import { Assert , AssertNot , IsEqual } from './test-utils/types' ;
68import { withMutations } from './with-mutations' ;
79
810type Param =
@@ -534,4 +536,53 @@ describe('withMutations with rxMutation', () => {
534536 error : 'Test-Error' ,
535537 } ) ;
536538 } ) ;
539+
540+ it ( 'does not expose mutation properties directly, only the method' , async ( ) => {
541+ // Test case for https://github.com/angular-architects/ngrx-toolkit/issues/286
542+ const testSetup = createTestSetup ( switchOp ) ;
543+ const store = testSetup . store ;
544+
545+ expect ( typeof store . increment ) . toEqual ( 'function' ) ;
546+ // @ts -expect-error Should not expose properties, only the method
547+ expect ( store . increment . isPending ) . toBeUndefined ( ) ;
548+ } ) ;
549+
550+ it ( 'types mutation method as plain callable Promise signature and returns nothing else from a mutation' , ( ) => {
551+ // Test case for https://github.com/angular-architects/ngrx-toolkit/issues/286
552+ const testSetup = createTestSetup ( ) ;
553+ const store = testSetup . store ;
554+
555+ // Only the method is exposed
556+ type _T1 = Assert <
557+ IsEqual <
558+ typeof store . increment ,
559+ ( params : Param ) => Promise < MutationResult < number > >
560+ >
561+ > ;
562+
563+ // Other mutation properties not present
564+ type _T2 = AssertNot <
565+ IsEqual < typeof store . increment , Mutation < Param , number > >
566+ > ;
567+
568+ // _T2 in other words:
569+
570+ // CAN...
571+ // Still can call mutation function
572+ store . increment ( 0 ) ;
573+
574+ // CANNOT...
575+ // @ts -expect-error should not expose properties, only method call
576+ const status = store . increment . status ;
577+ // @ts -expect-error should not expose properties, only method call
578+ const value = store . increment . value ;
579+ // @ts -expect-error should not expose properties, only method call
580+ const isPending = store . increment . isPending ;
581+ // @ts -expect-error should not expose properties, only method call
582+ const isSuccess = store . increment . isSuccess ;
583+ // @ts -expect-error should not expose properties, only method call
584+ const error = store . increment . error ;
585+ // @ts -expect-error should not expose properties, only method call
586+ const hasValue = store . increment . hasValue ;
587+ } ) ;
537588} ) ;
0 commit comments