import actionCreatorFactory , { isType , AnyAction } from "typescript-fsa" ; declare const action ; const actionCreator = actionCreatorFactory ( ) ; function testPayload ( ) { const withPayload = actionCreator < { foo : string ; } > ( 'WITH_PAYLOAD' ) ; const withoutPayload = actionCreator ( 'WITHOUT_PAYLOAD' ) ; const a = withPayload ( ) ; const b = withPayload ( { bar : 1 } ) ; const c = withPayload ( { foo : 'bar' } ) ; const d = withPayload ( { foo : 'bar' } , { meta : 'meta' } ) ; const e = withoutPayload ( ) ; const f = withoutPayload ( undefined , { meta : 'meta' } ) ; const g = withoutPayload ( { foo : 'bar' } ) ; } function testAsyncPayload ( ) { const async = actionCreator . async < { foo : string ; } , { bar : string ; } , { baz : string ; } > ( 'ASYNC' ) ; const started = async . started ( { foo : 'foo' } ) ; const started1 = async . started ( { } ) ; const started2 = async . started ( ) ; const done = async . done ( { params : { foo : 'foo' } , result : { bar : 'bar' } } ) ; const done1 = async . done ( { params : { foo : 1 } , result : { bar : 'bar' } } ) ; const done2 = async . done ( { params : { foo : 'foo' } , result : { bar : 1 } } ) ; const failed = async . failed ( { params : { foo : 'foo' } , error : { baz : 'baz' } } ) ; const failed1 = async . failed ( { params : { foo : 1 } , error : { baz : 'baz' } } ) ; const failed2 = async . failed ( { params : { foo : 'foo' } , error : { baz : 1 } } ) ; } function testAsyncNoParams ( ) { const asyncNoParams = actionCreator . async < void , { bar : string ; } , { baz : string ; } > ( 'ASYNC_NO_PARAMS' ) ; const started = asyncNoParams . started ( ) ; const started1 = asyncNoParams . started ( { foo : 'foo' } ) ; const done = asyncNoParams . done ( { result : { bar : 'bar' } } ) ; const done1 = asyncNoParams . done ( { params : { foo : 'foo' } , result : { bar : 'bar' } } ) ; const done2 = asyncNoParams . done ( { result : { bar : 1 } } ) ; const failed = asyncNoParams . failed ( { error : { baz : 'baz' } } ) ; const failed1 = asyncNoParams . failed ( { params : { foo : 'foo' } , error : { baz : 'baz' } } ) ; const failed2 = asyncNoParams . failed ( { error : { baz : 1 } } ) ; } function testAsyncNoResult ( ) { const asyncNoResult = actionCreator . async < { foo : string ; } , void , { baz : string ; } > ( 'ASYNC_NO_RESULT' ) ; const started = asyncNoResult . started ( { foo : 'foo' } ) ; const started1 = asyncNoResult . started ( { } ) ; const started2 = asyncNoResult . started ( ) ; const done = asyncNoResult . done ( { params : { foo : 'foo' } } ) ; const done1 = asyncNoResult . done ( { params : { foo : 1 } } ) ; const done2 = asyncNoResult . done ( { params : { foo : 'foo' } , result : { bar : 'bar' } } ) ; const failed = asyncNoResult . failed ( { params : { foo : 'foo' } , error : { baz : 'baz' } } ) ; const failed1 = asyncNoResult . failed ( { params : { foo : 1 } , error : { baz : 'baz' } } ) ; const failed2 = asyncNoResult . failed ( { params : { foo : 'foo' } , error : { baz : 1 } } ) ; } function testAsyncNoParamsAndResult ( ) { const async = actionCreator . async < void , void , { baz : string ; } > ( 'ASYNC' ) ; const started = async . started ( ) ; const started2 = async . started ( { foo : 'foo' } ) ; const done = async . done ( { } ) ; const done1 = async . done ( { params : { foo : 'foo' } } ) ; const done2 = async . done ( { result : { bar : 'bar' } } ) ; const failed = async . failed ( { error : { baz : 'baz' } } ) ; const failed1 = async . failed ( { params : { foo : 'foo' } , error : { baz : 'baz' } } ) ; } function testAsyncGeneric < P , R > ( params , result ) { const async = actionCreator . async < P , R > ( 'ASYNC' ) ; const started = async . started ( params ) ; const started1 = async . started ( { } ) ; const started2 = async . started ( ) ; const done = async . done ( { params , result } ) ; const done1 = async . done ( { params : { foo : 1 } , result } ) ; const done2 = async . done ( { params , result : { bar : 1 } } ) ; const failed = async . failed ( { params , error : { baz : 'baz' } } ) ; const failed1 = async . failed ( { params : { foo : 1 } , error : { baz : 'baz' } } ) ; } function testAsyncGenericStrictError < P , R , E > ( params , result , error ) { const async = actionCreator . async < P , R , E > ( 'ASYNC' ) ; const started = async . started ( params ) ; const started1 = async . started ( { } ) ; const started2 = async . started ( ) ; const done = async . done ( { params , result } ) ; const done1 = async . done ( { params : { foo : 1 } , result } ) ; const done2 = async . done ( { params , result : { bar : 1 } } ) ; const failed = async . failed ( { params , error } ) ; const failed1 = async . failed ( { params : { foo : 1 } , error } ) ; const failed2 = async . failed ( { params , error : { baz : 1 } } ) ; } function testIsType ( ) { const withPayload = actionCreator < { foo : string ; } > ( 'WITH_PAYLOAD' ) ; const withoutPayload = actionCreator ( 'WITHOUT_PAYLOAD' ) ; if ( isType ( action , withPayload ) ) { const foo = action . payload . foo ; action . payload . bar ; } if ( isType ( action , withoutPayload ) ) { const foo = action . payload ; } } function testMatch ( ) { const withPayload = actionCreator < { foo : string ; } > ( 'WITH_PAYLOAD' ) ; const withoutPayload = actionCreator ( 'WITHOUT_PAYLOAD' ) ; if ( withPayload . match ( action ) ) { const foo = action . payload . foo ; action . payload . bar ; } if ( withoutPayload . match ( action ) ) { const foo = action . payload ; } } function testMeta ( ) { const a = actionCreator < { foo : string ; } > ( '' ) ; a ( { foo : 'foo' } ) ; a ( { foo : 'foo' } , null ) ; a ( { foo : 'foo' } , 1 ) ; a ( { foo : 'foo' } , 'foo' ) ; a ( { foo : 'foo' } , true ) ; const action = a ( { foo : 'foo' } , { bar : 'baz' } ) ; action . meta . foo ; action . meta ! . foo ; }