From 29d283ca5c049da1830a8cb7f572701fccef6101 Mon Sep 17 00:00:00 2001 From: Kanitkorn Sujautra Date: Tue, 9 Oct 2018 00:21:41 +0700 Subject: [PATCH] [redux-immutable] Upgrade type definition to support Redux v4 + Immutable v4 (#29334) * [redux-immutable] Move the current version to v3 subfolder * [redux-immutable] Copied v3 over to root and update it to v4 --- types/redux-immutable/index.d.ts | 11 ++- types/redux-immutable/package.json | 4 +- .../redux-immutable/redux-immutable-tests.ts | 23 +++++- types/redux-immutable/v3/index.d.ts | 12 +++ types/redux-immutable/v3/package.json | 7 ++ .../v3/redux-immutable-tests.ts | 22 ++++++ types/redux-immutable/v3/tsconfig.json | 29 +++++++ types/redux-immutable/v3/tslint.json | 79 +++++++++++++++++++ 8 files changed, 179 insertions(+), 8 deletions(-) create mode 100644 types/redux-immutable/v3/index.d.ts create mode 100644 types/redux-immutable/v3/package.json create mode 100644 types/redux-immutable/v3/redux-immutable-tests.ts create mode 100644 types/redux-immutable/v3/tsconfig.json create mode 100644 types/redux-immutable/v3/tslint.json diff --git a/types/redux-immutable/index.d.ts b/types/redux-immutable/index.d.ts index 4b72685cc2..e712f663f0 100644 --- a/types/redux-immutable/index.d.ts +++ b/types/redux-immutable/index.d.ts @@ -1,12 +1,15 @@ -// Type definitions for redux-immutable v3.0.33 +// Type definitions for redux-immutable v4.0.0 // Project: https://github.com/gajus/redux-immutable // Definitions by: Pedro Pereira // Sebastian Sebald // Gavin Gregory +// Kanitkorn Sujautra // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 -import * as Redux from 'redux'; +import { ReducersMapObject, Reducer, Action } from 'redux'; import { Collection } from 'immutable'; -export declare function combineReducers(reducers: Redux.ReducersMapObject, getDefaultState?: () => Collection.Keyed): Redux.Reducer; -export declare function combineReducers(reducers: Redux.ReducersMapObject, getDefaultState?: () => Collection.Indexed): Redux.Reducer; +export declare function combineReducers(reducers: ReducersMapObject, getDefaultState?: () => Collection.Keyed): Reducer; +export declare function combineReducers(reducers: ReducersMapObject, getDefaultState?: () => Collection.Indexed): Reducer; +export declare function combineReducers(reducers: ReducersMapObject, getDefaultState?: () => Collection.Indexed): Reducer; diff --git a/types/redux-immutable/package.json b/types/redux-immutable/package.json index c5591e5012..c6e856bfdf 100644 --- a/types/redux-immutable/package.json +++ b/types/redux-immutable/package.json @@ -1,7 +1,7 @@ { "private": true, "dependencies": { - "redux": "^3.6.0", - "immutable": "^3.8.1" + "redux": "^4.0.0", + "immutable": "^4.0.0-rc.1" } } diff --git a/types/redux-immutable/redux-immutable-tests.ts b/types/redux-immutable/redux-immutable-tests.ts index c790ce545e..00ae820a43 100644 --- a/types/redux-immutable/redux-immutable-tests.ts +++ b/types/redux-immutable/redux-immutable-tests.ts @@ -1,6 +1,7 @@ import { combineReducers } from 'redux-immutable'; import { Map, List } from 'immutable'; +import { AnyAction } from 'redux'; // Dummy State interface interface State { }; @@ -11,11 +12,29 @@ interface State { }; combineReducers({}); combineReducers({}); +/** + * Combine reducers support reducer with custom action + */ +combineReducers({ + reducerNumber: (state: number, action: { type: string; payload: number }) => { + switch(action.type) { + case 'multiply': return state * action.payload + default: return state + } + }, + reducerString: (state: string, action: { type: string; payload: string }) => { + switch(action.type) { + case 'concat': return state.concat(action.payload) + default: return state + } + }, +}); + /** * Combine reducers should accepts a function (getDefaultState()) as a second parameter, that returns an immutable Collection.Keyed collection. */ -combineReducers({}, () => { return Map(); }); -combineReducers({}, () => { return Map(); }); +combineReducers({}, () => { return Map(); }); +combineReducers({}, () => { return Map(); }); /** * Combine reducers should accepts a function (getDefaultState()) as a second parameter, that returns an immutable Collection.Indexed collection. */ diff --git a/types/redux-immutable/v3/index.d.ts b/types/redux-immutable/v3/index.d.ts new file mode 100644 index 0000000000..4b72685cc2 --- /dev/null +++ b/types/redux-immutable/v3/index.d.ts @@ -0,0 +1,12 @@ +// Type definitions for redux-immutable v3.0.33 +// Project: https://github.com/gajus/redux-immutable +// Definitions by: Pedro Pereira +// Sebastian Sebald +// Gavin Gregory +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import * as Redux from 'redux'; +import { Collection } from 'immutable'; + +export declare function combineReducers(reducers: Redux.ReducersMapObject, getDefaultState?: () => Collection.Keyed): Redux.Reducer; +export declare function combineReducers(reducers: Redux.ReducersMapObject, getDefaultState?: () => Collection.Indexed): Redux.Reducer; diff --git a/types/redux-immutable/v3/package.json b/types/redux-immutable/v3/package.json new file mode 100644 index 0000000000..c5591e5012 --- /dev/null +++ b/types/redux-immutable/v3/package.json @@ -0,0 +1,7 @@ +{ + "private": true, + "dependencies": { + "redux": "^3.6.0", + "immutable": "^3.8.1" + } +} diff --git a/types/redux-immutable/v3/redux-immutable-tests.ts b/types/redux-immutable/v3/redux-immutable-tests.ts new file mode 100644 index 0000000000..c790ce545e --- /dev/null +++ b/types/redux-immutable/v3/redux-immutable-tests.ts @@ -0,0 +1,22 @@ + +import { combineReducers } from 'redux-immutable'; +import { Map, List } from 'immutable'; + +// Dummy State interface +interface State { }; + +/** + * Combine reducers should work with only one argument (a reducers object). + */ +combineReducers({}); +combineReducers({}); + +/** + * Combine reducers should accepts a function (getDefaultState()) as a second parameter, that returns an immutable Collection.Keyed collection. + */ +combineReducers({}, () => { return Map(); }); +combineReducers({}, () => { return Map(); }); +/** + * Combine reducers should accepts a function (getDefaultState()) as a second parameter, that returns an immutable Collection.Indexed collection. + */ +combineReducers({}, () => { return List(); }); diff --git a/types/redux-immutable/v3/tsconfig.json b/types/redux-immutable/v3/tsconfig.json new file mode 100644 index 0000000000..68cf5b5b78 --- /dev/null +++ b/types/redux-immutable/v3/tsconfig.json @@ -0,0 +1,29 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": false, + "strictNullChecks": false, + "strictFunctionTypes": true, + "baseUrl": "../../", + "typeRoots": [ + "../../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "paths": { + "redux-immutable": [ + "redux-immutable/v3" + ] + } + }, + "files": [ + "index.d.ts", + "redux-immutable-tests.ts" + ] +} \ No newline at end of file diff --git a/types/redux-immutable/v3/tslint.json b/types/redux-immutable/v3/tslint.json new file mode 100644 index 0000000000..a41bf5d19a --- /dev/null +++ b/types/redux-immutable/v3/tslint.json @@ -0,0 +1,79 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "adjacent-overload-signatures": false, + "array-type": false, + "arrow-return-shorthand": false, + "ban-types": false, + "callable-types": false, + "comment-format": false, + "dt-header": false, + "eofline": false, + "export-just-namespace": false, + "import-spacing": false, + "interface-name": false, + "interface-over-type-literal": false, + "jsdoc-format": false, + "max-line-length": false, + "member-access": false, + "new-parens": false, + "no-any-union": false, + "no-boolean-literal-compare": false, + "no-conditional-assignment": false, + "no-consecutive-blank-lines": false, + "no-construct": false, + "no-declare-current-package": false, + "no-duplicate-imports": false, + "no-duplicate-variable": false, + "no-empty-interface": false, + "no-for-in-array": false, + "no-inferrable-types": false, + "no-internal-module": false, + "no-irregular-whitespace": false, + "no-mergeable-namespace": false, + "no-misused-new": false, + "no-namespace": false, + "no-object-literal-type-assertion": false, + "no-padding": false, + "no-redundant-jsdoc": false, + "no-redundant-jsdoc-2": false, + "no-redundant-undefined": false, + "no-reference-import": false, + "no-relative-import-in-test": false, + "no-self-import": false, + "no-single-declare-module": false, + "no-string-throw": false, + "no-unnecessary-callback-wrapper": false, + "no-unnecessary-class": false, + "no-unnecessary-generics": false, + "no-unnecessary-qualifier": false, + "no-unnecessary-type-assertion": false, + "no-useless-files": false, + "no-var-keyword": false, + "no-var-requires": false, + "no-void-expression": false, + "no-trailing-whitespace": false, + "object-literal-key-quotes": false, + "object-literal-shorthand": false, + "one-line": false, + "one-variable-per-declaration": false, + "only-arrow-functions": false, + "prefer-conditional-expression": false, + "prefer-const": false, + "prefer-declare-function": false, + "prefer-for-of": false, + "prefer-method-signature": false, + "prefer-template": false, + "radix": false, + "semicolon": false, + "space-before-function-paren": false, + "space-within-parens": false, + "strict-export-declare-modifiers": false, + "trim-file": false, + "triple-equals": false, + "typedef-whitespace": false, + "unified-signatures": false, + "void-return": false, + "whitespace": false + } +}