added type definitions for multireducer (#35776)

* added type definitions for multireducer

* added type definitions for multireducer fixed issues
This commit is contained in:
immigration9 2019-05-29 05:48:39 +09:00 committed by Sheetal Nandi
parent 369612c7c8
commit 8ce8f37634
4 changed files with 70 additions and 0 deletions

20
types/multireducer/index.d.ts vendored Normal file
View File

@ -0,0 +1,20 @@
// Type definitions for multireducer 3.1
// Project: https://github.com/erikras/multireducer
// Definitions by: Anthony M. Lee <https://github.com/immigration9>
// 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;

View File

@ -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);

View File

@ -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"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }