Skip to content

Commit 8466262

Browse files
timdorrcellognickservjedmao
authored
Merge pull request reduxjs#3536 from reduxjs/ts-conversion
[Meta PR] Convert to TypeScript Co-authored-by: Gregory Beaver <greg.beaver.cello@gmail.com> Co-authored-by: Nick McCurdy <nick@nickmccurdy.com> Co-authored-by: Jed Mao <jedmao@users.noreply.github.com> Former-commit-id: 3b4f495 Former-commit-id: d429872
2 parents 80d7c23 + b2dd15b commit 8466262

File tree

61 files changed

+135
-78
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+135
-78
lines changed

Diff for: .babelrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const { NODE_ENV } = process.env
22

33
module.exports = {
44
presets: [
5+
'@babel/typescript',
56
[
67
'@babel/env',
78
{

Diff for: .eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
**/server.js
44
**/webpack.config*.js
55
**/flow-typed/**
6+
# TODO: figure out a way to lint this using flow instead of typescript
7+
examples/todos-flow

Diff for: .eslintrc.js

+23-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,34 @@
11
module.exports = {
22
extends: 'react-app',
33

4+
parser: '@typescript-eslint/parser',
5+
6+
plugins: ['@typescript-eslint'],
7+
48
settings: {
59
react: {
610
version: '16.8'
11+
},
12+
'import/parsers': {
13+
'@typescript-eslint/parser': ['.ts', '.tsx']
14+
},
15+
'import/resolver': {
16+
// use <root>/tsconfig.json
17+
typescript: {}
718
}
819
},
920

1021
rules: {
11-
'jsx-a11y/href-no-hash': 'off'
12-
},
13-
14-
overrides: [
15-
{
16-
files: 'test/**/*.js',
17-
env: {
18-
jest: true,
19-
},
20-
},
21-
],
22+
'jsx-a11y/href-no-hash': 'off',
23+
'no-unused-vars': 'off',
24+
'@typescript-eslint/no-unused-vars': [
25+
'error',
26+
{
27+
vars: 'all',
28+
args: 'after-used',
29+
ignoreRestSiblings: true,
30+
argsIgnorePattern: '^_' // ignore unused variables whose name is '_'
31+
}
32+
]
33+
}
2234
}

Diff for: .gitignore

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
.DS_Store
2-
*.log
31
node_modules
2+
3+
coverage
4+
45
dist
56
lib
67
es
7-
coverage
8+
types
89

910
website/translated_docs
1011
website/build/

Diff for: examples/todomvc/src/components/App.spec.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import App from './App'
44
import Header from '../containers/Header'
55
import MainSection from '../containers/MainSection'
66

7-
8-
const setup = propOverrides => {
7+
const setup = _propOverrides => {
98
const renderer = createRenderer()
109
renderer.render(<App />)
1110
const output = renderer.getRenderOutput()
@@ -16,16 +15,16 @@ describe('components', () => {
1615
describe('Header', () => {
1716
it('should render', () => {
1817
const output = setup()
19-
const [ header ] = output.props.children
18+
const [header] = output.props.children
2019
expect(header.type).toBe(Header)
2120
})
2221
})
23-
22+
2423
describe('Mainsection', () => {
2524
it('should render', () => {
2625
const output = setup()
27-
const [ , mainSection ] = output.props.children
26+
const [, mainSection] = output.props.children
2827
expect(mainSection.type).toBe(MainSection)
2928
})
3029
})
31-
})
30+
})

Diff for: index.d.ts.REMOVED.git-id

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
50e8d018faee8887ed82337fcd1993ad07df0968
1+
aa8ec2ad318f2542aaf407c9112143f8669dba4e

Diff for: package-lock.json.REMOVED.git-id

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json.REMOVED.git-id

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6dc69e8d7768ccf0b08dd7b6ed73f57ce5ba7510
1+
772f99d6b51677bd2cd88345904b9e29c40eb9bd

Diff for: rollup.config.js.REMOVED.git-id

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
07297f2bc2205b6f21539ca6f1c50d96d4cb9096
1+
27ce0b7bc959177b6a0d4a3dd4ae43fe27f476d3

Diff for: src/applyMiddleware.js.REMOVED.git-id

-1
This file was deleted.

Diff for: src/applyMiddleware.ts.REMOVED.git-id

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
f73584325282b69e12dd6caa61ae5bf23c32e64f

Diff for: src/bindActionCreators.js.REMOVED.git-id

-1
This file was deleted.

Diff for: src/bindActionCreators.ts.REMOVED.git-id

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
073a3b58df26f159289b9e854cfd615af6ed9bc9

Diff for: src/combineReducers.js.REMOVED.git-id

-1
This file was deleted.

Diff for: src/combineReducers.ts.REMOVED.git-id

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
07f9f7bd22ae1cc4dd9a295731960e1e90aac88e

Diff for: src/compose.js

-22
This file was deleted.

Diff for: src/compose.ts.REMOVED.git-id

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fcbfd70d7bf2aa262de58be558c4a6008957e7f0

Diff for: src/createStore.js.REMOVED.git-id

-1
This file was deleted.

Diff for: src/createStore.ts.REMOVED.git-id

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a75fc2a304526089ddb4af859689430dc4e4b3c6

Diff for: src/index.js.REMOVED.git-id

-1
This file was deleted.

Diff for: src/index.ts.REMOVED.git-id

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
40df5f346de6cd075ce8946e0fa1aa778e9cbc09

Diff for: src/types/actions.ts.REMOVED.git-id

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
75215ed7afdeaf3f2e973109805cc779557c8bfb

Diff for: src/types/middleware.ts.REMOVED.git-id

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
d631d988daabb5d9d72c5821122fede3a8e705b2

Diff for: src/types/reducers.ts.REMOVED.git-id

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
d0c41a9d33ce27ca26c1a283564be5b04a6d55e3

Diff for: src/types/store.ts.REMOVED.git-id

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
aaebb0ad21e3f200568600eb568abbec514e7111
File renamed without changes.

Diff for: src/utils/isPlainObject.js renamed to src/utils/isPlainObject.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
2-
* @param {any} obj The object to inspect.
3-
* @returns {boolean} True if the argument appears to be a plain object.
2+
* @param obj The object to inspect.
3+
* @returns True if the argument appears to be a plain object.
44
*/
5-
export default function isPlainObject(obj) {
5+
export default function isPlainObject(obj: any): boolean {
66
if (typeof obj !== 'object' || obj === null) return false
77

88
let proto = obj

Diff for: src/utils/warning.js renamed to src/utils/warning.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
/**
22
* Prints a warning in the console if it exists.
33
*
4-
* @param {String} message The warning message.
5-
* @returns {void}
4+
* @param message The warning message.
65
*/
7-
export default function warning(message) {
6+
export default function warning(message: string): void {
87
/* eslint-disable no-console */
98
if (typeof console !== 'undefined' && typeof console.error === 'function') {
109
console.error(message)

Diff for: test/applyMiddleware.spec.js.REMOVED.git-id

-1
This file was deleted.

Diff for: test/applyMiddleware.spec.ts.REMOVED.git-id

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fefd849b15428a4a294651edc81a3cb7fc373893

Diff for: test/bindActionCreators.spec.js.REMOVED.git-id

-1
This file was deleted.

Diff for: test/bindActionCreators.spec.ts.REMOVED.git-id

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5efecb6902f7abeab5af8892f778346c4bcaeaf7

Diff for: test/combineReducers.spec.js.REMOVED.git-id

-1
This file was deleted.

Diff for: test/combineReducers.spec.ts.REMOVED.git-id

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
161e00658b64c2fa549317d5b6f68bc83f8646fe

Diff for: test/compose.spec.js.REMOVED.git-id

-1
This file was deleted.

Diff for: test/compose.spec.ts.REMOVED.git-id

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
d25131cdebad8959ef7eba061752516823b623a8

Diff for: test/createStore.spec.js.REMOVED.git-id

-1
This file was deleted.

Diff for: test/createStore.spec.ts.REMOVED.git-id

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5e8ef1db50fc59beceb2aee464b31644368a3669

Diff for: test/helpers/actionCreators.js.REMOVED.git-id

-1
This file was deleted.

Diff for: test/helpers/actionCreators.ts.REMOVED.git-id

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
46964ea9cef1aec64487cde982fc7450877410d7
File renamed without changes.

Diff for: test/helpers/middleware.js

-4
This file was deleted.

Diff for: test/helpers/middleware.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { MiddlewareAPI, Dispatch, AnyAction } from '../..'
2+
3+
type ThunkAction<T extends any = any> = T extends AnyAction
4+
? AnyAction
5+
: T extends Function
6+
? T
7+
: never
8+
9+
export function thunk({ dispatch, getState }: MiddlewareAPI) {
10+
return (next: Dispatch) => <T>(action: ThunkAction) =>
11+
typeof action === 'function' ? action(dispatch, getState) : next(action)
12+
}

Diff for: test/helpers/reducers.js.REMOVED.git-id

-1
This file was deleted.

Diff for: test/helpers/reducers.ts.REMOVED.git-id

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
c10d3d017ed4b5122d25d5ed2b80309ccadf7cf9

Diff for: test/replaceReducers.spec.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { createStore, combineReducers } from '..'
2+
3+
describe('replaceReducers test', () => {
4+
it('returns the original store', () => {
5+
const nextReducer = combineReducers({
6+
foo: (state = 1, _action) => state,
7+
bar: (state = 2, _action) => state
8+
})
9+
const store = createStore((state, action) => {
10+
if (state === undefined) return { type: 5 }
11+
return action
12+
})
13+
14+
const nextStore = store.replaceReducer(nextReducer)
15+
16+
expect(nextStore).toBe(store)
17+
})
18+
})
File renamed without changes.

Diff for: test/typescript/.eslintrc.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
rules: {
3+
'no-unused-expressions': 'off',
4+
'@typescript-eslint/no-namespace': 'off',
5+
'@typescript-eslint/no-unused-vars': 'off'
6+
}
7+
}

Diff for: test/typescript/actionCreators.ts.REMOVED.git-id

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e3594a0712d844fe26a2d8836137624dd9e1e73c
1+
f7a15bcd754e609d63e23bddd636288c72d72c1b

Diff for: test/typescript/actions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Action as ReduxAction } from 'redux'
1+
import { Action as ReduxAction } from '../..'
22

33
namespace FSA {
44
interface Action<P> extends ReduxAction {

Diff for: test/typescript/compose.ts.REMOVED.git-id

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ae2fc5b32dba9f6959659bfcfc901d366ce0217a
1+
cfc608bad3e6370697f8f4ae049df1efc823cd8f

Diff for: test/typescript/dispatch.ts.REMOVED.git-id

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
72f89988562262cb211a90298d9ca75c3b37bfa4
1+
9cb125e37a001777f5a3a86146a6b06a746cbbf9

Diff for: test/typescript/enhancers.ts.REMOVED.git-id

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7259b4884bf70423a7abbd95ced2ef45a9a760c1
1+
c6d29af6a08539a343f95fedf50be0f8a2927bfa

Diff for: test/typescript/injectedDispatch.ts.REMOVED.git-id

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
f115b699fe3596e938591ff39767c65032362da0
1+
46dc9a70160a8144aae157d53f4180200b6e4f13

Diff for: test/typescript/middleware.ts.REMOVED.git-id

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7b1c48443c1f0e03751a219d2a4f97258efabfd5
1+
a0f9afa7f68a7af687107984478c7c4b74367dbd

Diff for: test/typescript/reducers.ts.REMOVED.git-id

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5a109eeecee5610220b77259d3b0ee175d8dbd74
1+
f013f83b37aaf1bf8d8183e2bc433a454fa56e9b

Diff for: test/typescript/replaceReducer.ts

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { combineReducers, createStore } from '../..'
2+
3+
/**
4+
* verify that replaceReducer maintains strict typing if the new types change
5+
*/
6+
const bar = (state = { value: 'bar' }) => state
7+
const baz = (state = { value: 'baz' }) => state
8+
const ACTION = {
9+
type: 'action'
10+
}
11+
12+
const originalCompositeReducer = combineReducers({ bar })
13+
const store = createStore(originalCompositeReducer)
14+
store.dispatch(ACTION)
15+
16+
const firstState = store.getState()
17+
firstState.bar.value
18+
// typings:expect-error
19+
firstState.baz.value
20+
21+
const nextStore = store.replaceReducer(combineReducers({ baz })) // returns -> { baz: { value: 'baz' }}
22+
23+
const nextState = nextStore.getState()
24+
// typings:expect-error
25+
nextState.bar.value
26+
nextState.baz.value

Diff for: test/typescript/store.ts.REMOVED.git-id

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
123464ce556358be71cad6cb468910c36c2f9a39
1+
dd7d76296eeac8dd7d6abc7d65a98e7f24bb5bba

Diff for: test/utils/isPlainObject.spec.js renamed to test/utils/isPlainObject.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('isPlainObject', () => {
1616
expect(isPlainObject(new Date())).toBe(false)
1717
expect(isPlainObject([1, 2, 3])).toBe(false)
1818
expect(isPlainObject(null)).toBe(false)
19-
expect(isPlainObject()).toBe(false)
19+
expect(isPlainObject(undefined)).toBe(false)
2020
expect(isPlainObject({ x: 1, y: 2 })).toBe(true)
2121
})
2222
})

Diff for: tsconfig.json.REMOVED.git-id

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1ef2e9f083e0338a4cf39a2cd6a11df70b0c3abc

0 commit comments

Comments
 (0)