Skip to content

Commit 12542a2

Browse files
tjallingtSimenB
authored andcommitted
Improve instructions for enabling typescript support (#7989)
1 parent 25133b3 commit 12542a2

2 files changed

Lines changed: 36 additions & 4 deletions

File tree

docs/GettingStarted.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,22 @@ Jest can be used in projects that use [webpack](https://webpack.github.io/) to m
151151

152152
### Using TypeScript
153153

154-
Jest supports TypeScript out of the box, via Babel.
154+
Jest supports TypeScript, via Babel. First make sure you followed the instructions on [using Babel](#using-babel) above. Next install the `@babel/preset-typescript` via `yarn`:
155155

156-
However, there are some caveats to using Typescript with Babel, see http://artsy.github.io/blog/2017/11/27/Babel-7-and-TypeScript/. Another caveat is that Jest will not typecheck your tests. If you want that, you can use [ts-jest](https://github.com/kulshekhar/ts-jest).
156+
```bash
157+
yarn add --dev @babel/preset-typescript
158+
```
159+
160+
Then add `@babel/preset-typescript` to the list of presets in your `babel.config.js`.
161+
162+
```javascript
163+
// babel.config.js
164+
module.exports = {
165+
presets: [
166+
['@babel/preset-env', {targets: {node: 'current'}}],
167+
'@babel/preset-typescript',
168+
],
169+
};
170+
```
171+
172+
Note that there are some caveats to using Typescript with Babel, see http://artsy.github.io/blog/2017/11/27/Babel-7-and-TypeScript/. Another caveat is that Jest will not typecheck your tests. If you want that, you can use [ts-jest](https://github.com/kulshekhar/ts-jest).

website/versioned_docs/version-24.0/GettingStarted.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,22 @@ Jest can be used in projects that use [webpack](https://webpack.github.io/) to m
152152

153153
### Using TypeScript
154154

155-
Jest supports TypeScript out of the box, via Babel.
155+
Jest supports TypeScript, via Babel. First make sure you followed the instructions on [using Babel](#using-babel) above. Next install the `@babel/preset-typescript` via `yarn`:
156156

157-
However, there are some caveats to using Typescript with Babel, see http://artsy.github.io/blog/2017/11/27/Babel-7-and-TypeScript/. Another caveat is that Jest will not typecheck your tests. If you want that, you can use [ts-jest](https://github.com/kulshekhar/ts-jest).
157+
```bash
158+
yarn add --dev @babel/preset-typescript
159+
```
160+
161+
Then add `@babel/preset-typescript` to the list of presets in your `babel.config.js`.
162+
163+
```javascript
164+
// babel.config.js
165+
module.exports = {
166+
presets: [
167+
['@babel/preset-env', {targets: {node: 'current'}}],
168+
'@babel/preset-typescript',
169+
],
170+
};
171+
```
172+
173+
Note that there are some caveats to using Typescript with Babel, see http://artsy.github.io/blog/2017/11/27/Babel-7-and-TypeScript/. Another caveat is that Jest will not typecheck your tests. If you want that, you can use [ts-jest](https://github.com/kulshekhar/ts-jest).

0 commit comments

Comments
 (0)