import identity from '@theatre/shared/utils/identity' ; import type { $IntentionalAny } from '@theatre/shared/utils/types' ; interface Transformer < Input extends $IntentionalAny , Output extends $IntentionalAny > { ( input ) : Output ; } type SubString < T > = T extends string ? ( string extends T ? never : T ) : never ; interface ActionCreatorCreator { < ActionType extends string , Payload , Input > ( actionType , transformer ) : { ( input ) : { type : SubString < ActionType > ; payload : Payload ; } ; type : SubString < ActionType > ; ActionType : { type : SubString < ActionType > ; payload : Payload ; } ; is : ( o : $IntentionalAny ) => o is { type : SubString < ActionType > ; payload : Payload ; } ; } ; < ActionType extends string > ( actionType ) : { < Payload > ( payload ) : { type : SubString < ActionType > ; payload : Payload ; } ; ( ) : { type : SubString < ActionType > ; payload : void ; } ; type : SubString < ActionType > ; ActionType : { type : SubString < ActionType > ; payload : unknown ; } ; is : ( o : unknown ) => o is { type : SubString < ActionType > ; payload : unknown ; } ; } ; } /**
 * This is basically the same as `{createAction}` from 'redux-actions',
 * only that you can query the type of the action from the resulting
 * action creator.
 */ const actionCreator = ( actionType , transformer = identity ) => { const originalActionCreator = ( payload ) => ( { type : actionType , payload : transformer ( payload ) } ) ; originalActionCreator . type = actionType ; originalActionCreator . is = ( o ) => o && o . type && o . type === actionType ; return originalActionCreator ; } ; export default actionCreator ;