Skip to content

Commit c81ec47

Browse files
cellogtimdorr
authored andcommitted
scaffolding for typescript (reduxjs#3504)
* scaffolding for typescript * add jest types so tests will compile * remove rollup-plugin-typescript2, probably don't need it * add missing eslint-import * fix linting errors Former-commit-id: 80cb6b8
1 parent 4d8662c commit c81ec47

10 files changed

+62
-19
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: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,43 @@
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'
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+
]
1233
},
1334

1435
overrides: [
1536
{
1637
files: 'test/**/*.js',
1738
env: {
18-
jest: true,
19-
},
20-
},
21-
],
39+
jest: true
40+
}
41+
}
42+
]
2243
}

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+
})

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: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
"test:watch": "npm test -- --watch",
4545
"test:cov": "npm test -- --coverage",
4646
"build": "rollup -c",
47-
"prepare": "npm run clean && npm run format:check && npm run lint && npm test",
47+
"prepare": "npm run clean && npm run check-types && npm run format:check && npm run lint && npm test",
48+
"check-types": "tsc",
4849
"examples:lint": "eslint examples",
4950
"examples:test": "cross-env CI=true babel-node examples/testAll.js"
5051
},
@@ -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",

rollup.config.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { DEFAULT_EXTENSIONS } from '@babel/core'
12
import nodeResolve from 'rollup-plugin-node-resolve'
23
import babel from 'rollup-plugin-babel'
34
import replace from 'rollup-plugin-replace'
@@ -14,7 +15,11 @@ export default [
1415
...Object.keys(pkg.dependencies || {}),
1516
...Object.keys(pkg.peerDependencies || {})
1617
],
17-
plugins: [babel()]
18+
plugins: [
19+
babel({
20+
extensions: [...DEFAULT_EXTENSIONS, '.ts']
21+
})
22+
]
1823
},
1924

2025
// ES
@@ -25,7 +30,11 @@ export default [
2530
...Object.keys(pkg.dependencies || {}),
2631
...Object.keys(pkg.peerDependencies || {})
2732
],
28-
plugins: [babel()]
33+
plugins: [
34+
babel({
35+
extensions: [...DEFAULT_EXTENSIONS, '.ts']
36+
})
37+
]
2938
},
3039

3140
// ES for Browsers
@@ -37,6 +46,10 @@ export default [
3746
replace({
3847
'process.env.NODE_ENV': JSON.stringify('production')
3948
}),
49+
babel({
50+
extensions: [...DEFAULT_EXTENSIONS, '.ts'],
51+
exclude: 'node_modules/**'
52+
}),
4053
terser({
4154
compress: {
4255
pure_getters: true,
@@ -60,6 +73,7 @@ export default [
6073
plugins: [
6174
nodeResolve(),
6275
babel({
76+
extensions: [...DEFAULT_EXTENSIONS, '.ts'],
6377
exclude: 'node_modules/**'
6478
}),
6579
replace({
@@ -80,6 +94,7 @@ export default [
8094
plugins: [
8195
nodeResolve(),
8296
babel({
97+
extensions: [...DEFAULT_EXTENSIONS, '.ts'],
8398
exclude: 'node_modules/**'
8499
}),
85100
replace({

test/applyMiddleware.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ describe('applyMiddleware', () => {
120120
}
121121

122122
function dummyMiddleware({ dispatch }) {
123-
return next => action => dispatch(action, testCallArgs)
123+
return _next => action => dispatch(action, testCallArgs)
124124
}
125125

126126
const store = createStore(
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6a837c0d1d9dcadcfbc483465a928cac701ff99d
1+
f3700e2d6d86c13c2302d46af03dbf9bfac16f4e

tsconfig.json.REMOVED.git-id

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
052d09d209c201be4d4cdbc8fcdf634b5172ab8c

0 commit comments

Comments
 (0)