Skip to content

Commit

Permalink
Improve flow typing for action method
Browse files Browse the repository at this point in the history
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 5cab298
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions flow-typed/mobx.js
Expand Up @@ -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;
Expand Down

0 comments on commit 5cab298

Please sign in to comment.