diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index 57d64640527d..2da889c273a8 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -151,6 +151,22 @@ Jest can be used in projects that use [webpack](https://webpack.github.io/) to m ### Using TypeScript -Jest supports TypeScript out of the box, via Babel. +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`: -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). +```bash +yarn add --dev @babel/preset-typescript +``` + +Then add `@babel/preset-typescript` to the list of presets in your `babel.config.js`. + +```javascript +// babel.config.js +module.exports = { + presets: [ + ['@babel/preset-env', {targets: {node: 'current'}}], + '@babel/preset-typescript', + ], +}; +``` + +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). diff --git a/website/versioned_docs/version-24.0/GettingStarted.md b/website/versioned_docs/version-24.0/GettingStarted.md index ae1d57d5a7f4..637d74655e12 100644 --- a/website/versioned_docs/version-24.0/GettingStarted.md +++ b/website/versioned_docs/version-24.0/GettingStarted.md @@ -152,6 +152,22 @@ Jest can be used in projects that use [webpack](https://webpack.github.io/) to m ### Using TypeScript -Jest supports TypeScript out of the box, via Babel. +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`: -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). +```bash +yarn add --dev @babel/preset-typescript +``` + +Then add `@babel/preset-typescript` to the list of presets in your `babel.config.js`. + +```javascript +// babel.config.js +module.exports = { + presets: [ + ['@babel/preset-env', {targets: {node: 'current'}}], + '@babel/preset-typescript', + ], +}; +``` + +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).