Skip to content

Commit d429872

Browse files
timdorrcellognickservjedmao
authored
Merge pull request reduxjs#3536 from reduxjs/ts-conversion
[Meta PR] Convert to TypeScript Co-authored-by: Gregory Beaver <[email protected]> Co-authored-by: Nick McCurdy <[email protected]> Co-authored-by: Jed Mao <[email protected]> Former-commit-id: 3b4f495
2 parents 9403497 + aaa10aa commit d429872

Some content is hidden

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

56 files changed

+743
-256
lines changed

.babelrc.js

Lines changed: 1 addition & 0 deletions
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
{

.eslintignore

Lines changed: 2 additions & 0 deletions
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

.eslintrc.js

Lines changed: 23 additions & 11 deletions
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
}

.gitignore

Lines changed: 4 additions & 3 deletions
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/

examples/todomvc/src/components/App.spec.js

Lines changed: 5 additions & 6 deletions
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+
})

index.d.ts.REMOVED.git-id

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
50e8d018faee8887ed82337fcd1993ad07df0968
1+
aa8ec2ad318f2542aaf407c9112143f8669dba4e

package-lock.json.REMOVED.git-id

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,27 @@
2626
"main": "lib/redux.js",
2727
"unpkg": "dist/redux.js",
2828
"module": "es/redux.js",
29-
"typings": "./index.d.ts",
29+
"types": "types/index.d.ts",
3030
"files": [
3131
"dist",
3232
"lib",
3333
"es",
3434
"src",
35-
"index.d.ts"
35+
"types"
3636
],
3737
"scripts": {
38-
"clean": "rimraf lib dist es coverage",
38+
"clean": "rimraf lib dist es coverage types",
3939
"format": "prettier --write \"{src,test}/**/*.{js,ts}\" index.d.ts \"**/*.md\"",
4040
"format:check": "prettier --list-different \"{src,test}/**/*.{js,ts}\" index.d.ts \"**/*.md\"",
41-
"lint": "eslint src test",
41+
"lint": "eslint --ext js,ts src test",
42+
"check-types": "tsc --noEmit",
4243
"pretest": "npm run build",
4344
"test": "jest",
4445
"test:watch": "npm test -- --watch",
4546
"test:cov": "npm test -- --coverage",
4647
"build": "rollup -c",
47-
"prepare": "npm run clean && npm run format:check && npm run lint && npm test",
48-
"examples:lint": "eslint examples",
48+
"prepare": "npm run clean && npm run check-types && npm run format:check && npm run lint && npm test",
49+
"examples:lint": "eslint --ext js,ts examples",
4950
"examples:test": "cross-env CI=true babel-node examples/testAll.js"
5051
},
5152
"dependencies": {
@@ -60,15 +61,18 @@
6061
"@babel/plugin-proposal-object-rest-spread": "^7.5.4",
6162
"@babel/preset-env": "^7.5.4",
6263
"@babel/preset-flow": "^7.0.0",
64+
"@babel/preset-typescript": "^7.3.3",
6365
"@babel/register": "^7.4.4",
64-
"@typescript-eslint/eslint-plugin": "^1.11.0",
65-
"@typescript-eslint/parser": "^1.11.0",
66+
"@types/jest": "^24.0.17",
67+
"@typescript-eslint/eslint-plugin": "^1.13.0",
68+
"@typescript-eslint/parser": "^1.13.0",
6669
"babel-core": "^7.0.0-bridge.0",
6770
"babel-eslint": "^10.0.2",
6871
"babel-jest": "^24.8.0",
6972
"cross-env": "^5.2.0",
7073
"eslint": "^5.16.0",
7174
"eslint-config-react-app": "^4.0.1",
75+
"eslint-import-resolver-typescript": "^1.1.1",
7276
"eslint-plugin-flowtype": "^2.50.3",
7377
"eslint-plugin-import": "^2.18.0",
7478
"eslint-plugin-jsx-a11y": "^6.2.3",
@@ -83,6 +87,7 @@
8387
"rollup-plugin-node-resolve": "^5.2.0",
8488
"rollup-plugin-replace": "^2.2.0",
8589
"rollup-plugin-terser": "^5.1.1",
90+
"rollup-plugin-typescript2": "^0.24.0",
8691
"rxjs": "^6.5.2",
8792
"typescript": "^3.5.3",
8893
"typings-tester": "^0.3.2"
@@ -102,7 +107,7 @@
102107
]
103108
},
104109
"jest": {
105-
"testRegex": "(/test/.*\\.spec\\.js)$"
110+
"testRegex": "(/test/.*\\.spec\\.[tj]s)$"
106111
},
107112
"sideEffects": false
108113
}

rollup.config.js

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,63 @@
11
import nodeResolve from 'rollup-plugin-node-resolve'
22
import babel from 'rollup-plugin-babel'
33
import replace from 'rollup-plugin-replace'
4+
import typescript from 'rollup-plugin-typescript2'
45
import { terser } from 'rollup-plugin-terser'
56

67
import pkg from './package.json'
78

9+
const noDeclarationFiles = { compilerOptions: { declaration: false } };
10+
811
export default [
912
// CommonJS
1013
{
11-
input: 'src/index.js',
14+
input: 'src/index.ts',
1215
output: { file: 'lib/redux.js', format: 'cjs', indent: false },
1316
external: [
1417
...Object.keys(pkg.dependencies || {}),
1518
...Object.keys(pkg.peerDependencies || {})
1619
],
17-
plugins: [babel()]
20+
plugins: [
21+
nodeResolve({
22+
extensions: ['.ts']
23+
}),
24+
typescript({ useTsconfigDeclarationDir: true }),
25+
babel()
26+
]
1827
},
1928

2029
// ES
2130
{
22-
input: 'src/index.js',
31+
input: 'src/index.ts',
2332
output: { file: 'es/redux.js', format: 'es', indent: false },
2433
external: [
2534
...Object.keys(pkg.dependencies || {}),
2635
...Object.keys(pkg.peerDependencies || {})
2736
],
28-
plugins: [babel()]
37+
plugins: [
38+
nodeResolve({
39+
extensions: ['.ts']
40+
}),
41+
typescript({ tsconfigOverride: noDeclarationFiles }),
42+
babel()
43+
]
2944
},
3045

3146
// ES for Browsers
3247
{
33-
input: 'src/index.js',
48+
input: 'src/index.ts',
3449
output: { file: 'es/redux.mjs', format: 'es', indent: false },
3550
plugins: [
36-
nodeResolve(),
51+
nodeResolve({
52+
extensions: ['.ts']
53+
}),
3754
replace({
3855
'process.env.NODE_ENV': JSON.stringify('production')
3956
}),
57+
typescript({ tsconfigOverride: noDeclarationFiles }),
58+
babel({
59+
exclude: 'node_modules/**'
60+
}),
4061
terser({
4162
compress: {
4263
pure_getters: true,
@@ -50,15 +71,18 @@ export default [
5071

5172
// UMD Development
5273
{
53-
input: 'src/index.js',
74+
input: 'src/index.ts',
5475
output: {
5576
file: 'dist/redux.js',
5677
format: 'umd',
5778
name: 'Redux',
5879
indent: false
5980
},
6081
plugins: [
61-
nodeResolve(),
82+
nodeResolve({
83+
extensions: ['.ts']
84+
}),
85+
typescript({ tsconfigOverride: noDeclarationFiles }),
6286
babel({
6387
exclude: 'node_modules/**'
6488
}),
@@ -70,15 +94,18 @@ export default [
7094

7195
// UMD Production
7296
{
73-
input: 'src/index.js',
97+
input: 'src/index.ts',
7498
output: {
7599
file: 'dist/redux.min.js',
76100
format: 'umd',
77101
name: 'Redux',
78102
indent: false
79103
},
80104
plugins: [
81-
nodeResolve(),
105+
nodeResolve({
106+
extensions: ['.ts']
107+
}),
108+
typescript({ tsconfigOverride: noDeclarationFiles }),
82109
babel({
83110
exclude: 'node_modules/**'
84111
}),

src/applyMiddleware.js

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)