diff --git a/redux-devtools/redux-devtools-tests.tsx b/redux-devtools/redux-devtools-tests.tsx index 196ac2214c..644596b9f1 100644 --- a/redux-devtools/redux-devtools-tests.tsx +++ b/redux-devtools/redux-devtools-tests.tsx @@ -15,7 +15,7 @@ const DevTools = createDevTools( ) -const finalCreateStore = compose( +const finalCreateStore = compose>( DevTools.instrument(), persistState('test-session') )(createStore) diff --git a/redux/index.d.ts b/redux/index.d.ts index b95a67609c..85adb5d398 100644 --- a/redux/index.d.ts +++ b/redux/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Redux v3.5.2 +// Type definitions for Redux v3.6.0 // Project: https://github.com/reactjs/redux // Definitions by: William Buchwalter , Vincent Prouillet , Kaur Kuut // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -15,11 +15,11 @@ declare namespace Redux { * * Actions must have a `type` field that indicates the type of action being * performed. Types can be defined as constants and imported from another - * module. It’s better to use strings for `type` than Symbols because strings + * module. It's better to use strings for `type` than Symbols because strings * are serializable. * * Other than `type`, the structure of an action object is really up to you. - * If you’re interested, check out Flux Standard Action for recommendations on + * If you're interested, check out Flux Standard Action for recommendations on * how actions should be constructed. */ interface Action { @@ -93,7 +93,7 @@ declare namespace Redux { * `dispatch` function provided by the store instance without any middleware. * * The base dispatch function *always* synchronously sends an action to the - * store’s reducer, along with the previous state returned by the store, to + * store's reducer, along with the previous state returned by the store, to * calculate a new state. It expects actions to be plain objects ready to be * consumed by the reducer. * @@ -114,7 +114,7 @@ declare namespace Redux { } /** - * A store is an object that holds the application’s state tree. + * A store is an object that holds the application's state tree. * There should only be a single store in a Redux app, as the composition * happens on the reducer level. * @@ -220,7 +220,7 @@ declare namespace Redux { * original store. There is an example in `compose` documentation * demonstrating that. * - * Most likely you’ll never write a store enhancer, but you may use the one + * Most likely you'll never write a store enhancer, but you may use the one * provided by the developer tools. It is what makes time travel possible * without the app being aware it is happening. Amusingly, the Redux * middleware implementation is itself a store enhancer. @@ -308,7 +308,7 @@ declare namespace Redux { * an action creator is a factory that creates an action. * * Calling an action creator only produces an action, but does not dispatch - * it. You need to call the store’s `dispatch` function to actually cause the + * it. You need to call the store's `dispatch` function to actually cause the * mutation. Sometimes we say *bound action creators* to mean functions that * call an action creator and immediately dispatch its result to a specific * store instance. @@ -366,6 +366,11 @@ declare namespace Redux { /* compose */ + type Func0 = () => R; + type Func1 = (a1: T1) => R; + type Func2 = (a1: T1, a2: T2) => R; + type Func3 = (a1: T1, a2: T2, a3: T3, ...args: any[]) => R; + /** * Composes single-argument functions from right to left. The rightmost * function can take multiple arguments as it provides the signature for the @@ -376,28 +381,56 @@ declare namespace Redux { * to left. For example, `compose(f, g, h)` is identical to doing * `(...args) => f(g(h(...args)))`. */ - function compose(): (a: R, ...args: any[]) => R; + function compose(): (a: R) => R; + function compose(f: F): F; + + /* two functions */ function compose( - f1: (b: A) => R, - f2: (...args: any[]) => A - ): (...args: any[]) => R; + f1: (b: A) => R, f2: Func0 + ): Func0; + function compose( + f1: (b: A) => R, f2: Func1 + ): Func1; + function compose( + f1: (b: A) => R, f2: Func2 + ): Func2; + function compose( + f1: (b: A) => R, f2: Func3 + ): Func3; + /* three functions */ function compose( - f1: (b: B) => R, - f2: (a: A) => B, - f3: (...args: any[]) => A - ): (...args: any[]) => R; + f1: (b: B) => R, f2: (a: A) => B, f3: Func0 + ): Func0; + function compose( + f1: (b: B) => R, f2: (a: A) => B, f3: Func1 + ): Func1; + function compose( + f1: (b: B) => R, f2: (a: A) => B, f3: Func2 + ): Func2; + function compose( + f1: (b: B) => R, f2: (a: A) => B, f3: Func3 + ): Func3; + /* four functions */ function compose( - f1: (b: C) => R, - f2: (a: B) => C, - f3: (a: A) => B, - f4: (...args: any[]) => A + f1: (b: C) => R, f2: (a: B) => C, f3: (a: A) => B, f4: Func0 + ): Func0; + function compose( + f1: (b: C) => R, f2: (a: B) => C, f3: (a: A) => B, f4: Func1 + ): Func1; + function compose( + f1: (b: C) => R, f2: (a: B) => C, f3: (a: A) => B, f4: Func2 + ): Func2; + function compose( + f1: (b: C) => R, f2: (a: B) => C, f3: (a: A) => B, f4: Func3 + ): Func3; + + /* rest */ + function compose( + f1: (b: any) => R, ...funcs: Function[] ): (...args: any[]) => R; - function compose( - f1: (a: any) => R, - ...funcs: Function[] - ): (...args: any[]) => R; -} \ No newline at end of file + function compose(...funcs: Function[]): (...args: any[]) => R; +} diff --git a/redux/redux-tests.ts b/redux/redux-tests.ts index 395c5fde7f..25138804ed 100644 --- a/redux/redux-tests.ts +++ b/redux/redux-tests.ts @@ -181,8 +181,22 @@ namespace EnumTypeAction { const t5: number = R.compose(stringToNumber, numberToString, numberToNumber)(5); const t6: string = R.compose(numberToString, stringToNumber, numberToString, numberToNumber)(5); - const t7: string = R.compose( + const t7: string = R.compose( numberToString, numberToNumber, stringToNumber, numberToString, stringToNumber)("fo"); + + + const multiArgFn = (a: string, b: number, c: boolean): string => 'foo'; + + const t8: string = R.compose(multiArgFn)('bar', 42, true); + const t9: number = R.compose(stringToNumber, multiArgFn)('bar', 42, true); + const t10: string = R.compose(numberToString, stringToNumber, + multiArgFn)('bar', 42, true); + + const t11: number = R.compose(stringToNumber, numberToString, stringToNumber, + multiArgFn)('bar', 42, true); + + const funcs = [stringToNumber, numberToString, stringToNumber]; + const t12 = R.compose(...funcs)('bar', 42, true); }()); // dispatch.ts @@ -383,4 +397,4 @@ declare module "redux" { } store.replaceReducer(newReducer); -}()); \ No newline at end of file +}());