Skip to content

Commit b0d4378

Browse files
author
Kent C. Dodds
committed
add typescript
1 parent e88f4ba commit b0d4378

6 files changed

Lines changed: 87 additions & 20 deletions

File tree

.babelrc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"node": "10"
88
}
99
}
10-
]
10+
],
11+
"@babel/preset-typescript"
1112
]
12-
}
13+
}

package-lock.json

Lines changed: 50 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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,22 @@
44
"author": "Kent C. Dodds (http://kentcdodds.com/)",
55
"license": "GPLv3",
66
"scripts": {
7-
"build": "babel src --out-dir dist",
7+
"build": "babel src --extensions .js,.ts,.tsx --out-dir dist",
88
"lint": "eslint --ignore-path .gitignore .",
9-
"prettier": "prettier --ignore-path .gitignore \"**/*.+(js|json)\"",
9+
"check-types": "tsc",
10+
"prettier": "prettier --ignore-path .gitignore \"**/*.+(js|json|ts|tsx)\"",
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.7.0",
1617
"@babel/core": "^7.7.2",
1718
"@babel/preset-env": "^7.7.1",
19+
"@babel/preset-typescript": "^7.7.2",
1820
"eslint": "^6.6.0",
1921
"eslint-config-prettier": "^6.5.0",
20-
"prettier": "^1.19.1"
22+
"prettier": "^1.19.1",
23+
"typescript": "^3.7.2"
2124
}
2225
}

src/typescript-example.js

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

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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"compilerOptions": {
3+
"noEmit": true,
4+
"baseUrl": "./src"
5+
}
6+
}

0 commit comments

Comments
 (0)