Skip to content
Permalink
Browse files
Improve flow typing for action method
This commit adds better flow typing for the `action()` method. Using
flowtype's method overloading feature, I have added two new type
definitions:

`action(name: string, func: T): T`
`action(func: T): T`

The existing `action()` type definition returned `any`, which caused
type information from passed wrapped functions to be lost. The new type
definitions return the same type of function that is passed as an
argument so that type information for the function is not lost when
wrapping the function in `action()`.

github.com/newoga
  • Loading branch information
newoga committed Feb 7, 2017
1 parent 94a11b1 commit 5cab2985fb0787ff3249315bd410f14a86896ac9
Showing 1 changed file with 2 additions and 0 deletions.
@@ -301,6 +301,8 @@ declare module 'mobx' {
declare function extendShallowObservable(target: any): any;

declare function action(targetOrName: any, propertyKeyOrFuc?: any, descriptor?: PropertyDescriptor): any;
declare function action<T>(name: string, func: T): T;
declare function action<T>(func: T): T;
declare function runInAction<T>(name: string, block: () => T, scope?: any): T;
declare function runInAction<T>(block: () => T, scope?: any): T;
declare function isAction(thing: any): boolean;

0 comments on commit 5cab298

Please sign in to comment.