Skip to content

Commit a5d2d97

Browse files
author
Kent C. Dodds
committed
add typescript
1 parent b41c948 commit a5d2d97

File tree

5 files changed

+139
-5
lines changed

5 files changed

+139
-5
lines changed

.eslintrc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
{
2+
"parser": "@typescript-eslint/parser",
23
"parserOptions": {
34
"ecmaVersion": 2019,
45
"sourceType": "module",
56
"ecmaFeatures": {
67
"jsx": true
7-
}
8+
},
9+
"project": "./tsconfig.json"
810
},
9-
"extends": ["eslint:recommended", "eslint-config-prettier"],
11+
"plugins": ["@typescript-eslint/eslint-plugin"],
12+
"extends": [
13+
"eslint:recommended",
14+
"plugin:@typescript-eslint/eslint-recommended",
15+
"plugin:@typescript-eslint/recommended",
16+
"eslint-config-prettier",
17+
"eslint-config-prettier/@typescript-eslint"
18+
],
1019
"rules": {
1120
"strict": ["error", "never"]
1221
},

package-lock.json

Lines changed: 91 additions & 0 deletions
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
@@ -5,18 +5,22 @@
55
"license": "GPLv3",
66
"scripts": {
77
"build": "babel src --out-dir dist",
8-
"lint": "eslint --ignore-path .gitignore .",
8+
"lint": "eslint --ignore-path .gitignore --ext .js,.ts,.tsx .",
9+
"check-types": "tsc",
910
"prettier": "prettier --ignore-path .gitignore --write \"**/*.+(js|json)\"",
1011
"format": "npm run prettier -- --write",
1112
"check-format": "npm run prettier -- --list-different",
12-
"validate": "npm run check-format && npm run lint && npm run build"
13+
"validate": "npm run check-types && npm run check-format && npm run lint && npm run build"
1314
},
1415
"devDependencies": {
1516
"@babel/cli": "^7.5.5",
1617
"@babel/core": "^7.5.5",
1718
"@babel/preset-env": "^7.5.5",
19+
"@typescript-eslint/eslint-plugin": "^2.0.0",
20+
"@typescript-eslint/parser": "^2.0.0",
1821
"eslint": "^6.1.0",
1922
"eslint-config-prettier": "^6.0.0",
20-
"prettier": "^1.18.2"
23+
"prettier": "^1.18.2",
24+
"typescript": "^3.5.3"
2125
}
2226
}

src/typescript-example.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function add(a: number, b: number): number {
2+
return a + b
3+
}
4+
5+
interface User {
6+
name: {
7+
first: string
8+
middle: string
9+
last: string
10+
}
11+
}
12+
function getFullName(user: User): string {
13+
const {
14+
name: {first, middle, last},
15+
} = user
16+
return [first, middle, last].filter(Boolean).join('')
17+
}
18+
19+
add(1, 2)
20+
21+
getFullName({name: {first: 'Joe', middle: 'Bud', last: 'Matthews'}})

tsconfig.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"compilerOptions": {
3+
// because we're compiling with Babel instead of TypeScript
4+
// and we're only using TypeScript for type checking, we'll set "noEmit"
5+
// to true so running type checking doesn't generate any files.
6+
"noEmit": true,
7+
"baseUrl": "./src"
8+
}
9+
}

0 commit comments

Comments
 (0)