deox
Version:
Functional Type-safe Flux Standard Utilities
24 lines (23 loc) • 730 B
TypeScript
/**
* Map action creator to it's contained action type
* @description it gets an object with at least a type property or overridden toString method and returns it.
* @example
* const increment = createActionCreator('[Counter] increment')
* getType(increment) //=> '[Counter] increment'
* @example
* getType({ type: 'TEST' }) //=> 'TEST'
* @example
* getType({
* toString() { return 'TEST' }
* }) //=> 'TEST'
*/
export declare function getType<TActionCreator extends {
type?: string;
toString(): string;
} | {
type: string;
}, TType extends string = TActionCreator extends {
type: infer T;
} ? T : TActionCreator extends {
toString(): infer U;
} ? U : never>(actionCreator: TActionCreator): TType;