diff --git a/types/multireducer/index.d.ts b/types/multireducer/index.d.ts new file mode 100644 index 0000000000..7d26ba1afb --- /dev/null +++ b/types/multireducer/index.d.ts @@ -0,0 +1,20 @@ +// Type definitions for multireducer 3.1 +// Project: https://github.com/erikras/multireducer +// Definitions by: Anthony M. Lee +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +export interface MetaObject { + [key: string]: string; +} + +export interface ActionObject { + meta: MetaObject; + [rest: string]: any; +} + +export function bindActionCreators(actions: any, dispatch: any, reducerKey: string): any; +export function wrapDispatch(dispatch: any, reducerKey: string): any; +export function wrapAction(action: any, reducerKey: string): ActionObject; + +export default function multireducer(reducers: { [key: string]: any }, reducerKey?: string): (state: any, action: any) => any; diff --git a/types/multireducer/multireducer-tests.ts b/types/multireducer/multireducer-tests.ts new file mode 100644 index 0000000000..e5392d2863 --- /dev/null +++ b/types/multireducer/multireducer-tests.ts @@ -0,0 +1,26 @@ +import multireducer from 'multireducer'; +import { deepEqual } from 'assert'; + +const initialState = { a: 1, b: 2, c: 3 }; + +const first = (state = initialState, action = {}) => { + return { ...state, a: 10 }; +}; + +const second = (state = initialState, action = {}) => { + return { ...state, b: 20 }; +}; + +const third = (state = initialState, action = {}) => { + return { ...state, c: 30 }; +}; + +const reducers = multireducer({ first, second, third })(undefined, {}); + +const expectedResult = { + first: { a: 10, b: 2, c: 3 }, + second: { a: 1, b: 20, c: 3 }, + third: { a: 1, b: 2, c: 30 } +}; + +deepEqual(reducers, expectedResult); diff --git a/types/multireducer/tsconfig.json b/types/multireducer/tsconfig.json new file mode 100644 index 0000000000..8651b2241e --- /dev/null +++ b/types/multireducer/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "multireducer-tests.ts" + ] +} diff --git a/types/multireducer/tslint.json b/types/multireducer/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/multireducer/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }