You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+1-3
Original file line number
Diff line number
Diff line change
@@ -142,7 +142,7 @@ Please refer to the [User Guide](https://facebook.github.io/create-react-app/doc
142
142
143
143
Your environment will have everything you need to build a modern single-page React app:
144
144
145
-
- React, JSX, ES6, and Flow syntax support.
145
+
- React, JSX, ES6, TypeScript and Flow syntax support.
146
146
- Language extras beyond ES6 like the object spread operator.
147
147
- Autoprefixed CSS, so you don’t need `-webkit-` or other prefixes.
148
148
- A fast interactive unit test runner with built-in support for coverage reporting.
@@ -175,8 +175,6 @@ Here’s a few common cases where you might want to try something else:
175
175
176
176
- If your website is **mostly static** (for example, a portfolio or a blog), consider using [Gatsby](https://www.gatsbyjs.org/) instead. Unlike Create React App, it pre-renders the website into HTML at the build time.
177
177
178
-
- If you want to use **TypeScript**, consider using [create-react-app-typescript](https://github.com/wmonk/create-react-app-typescript).
179
-
180
178
- Finally, if you need **more customization**, check out [Neutrino](https://neutrino.js.org/) and its [React preset](https://neutrino.js.org/packages/react/).
181
179
182
180
All of the above tools can work with little to no configuration.
TypeScript is a typed superset of JavaScript that compiles to plain JavaScript.
7
+
8
+
Recent versions of [TypeScript](https://www.typescriptlang.org/) work with Create React App projects out of the box thanks to Babel 7. Beware that Babel 7 TypeScript does not allow some features of TypeScript such as constant enum and namespaces.
9
+
10
+
To add TypeScript to a Create React App project, follow these steps:
2. Rename the `.js` files you want to convert. Use `.tsx` if they use JSX or `.ts` if not (e.g. `git mv src/index.js src/index.tsx`).
14
+
15
+
3. Create a [`tsconfig.json` file](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) at the root directory with the following content:
16
+
17
+
```json
18
+
{
19
+
"compilerOptions": {
20
+
"target": "es5",
21
+
"module": "esnext",
22
+
"moduleResolution": "node",
23
+
"lib": ["esnext", "dom", "dom.iterable"],
24
+
"allowJs": true,
25
+
"allowSyntheticDefaultImports": true,
26
+
"esModuleInterop": true,
27
+
"isolatedModules": true,
28
+
"jsx": "preserve",
29
+
"noEmit": true,
30
+
"skipLibCheck": true,
31
+
"strict": true
32
+
},
33
+
"include": ["src"]
34
+
}
35
+
```
36
+
37
+
4. Copy [loaders.d.ts](https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/src/loaders.d.ts) from the template to your `src` directory.
38
+
39
+
Type errors will show up in the same console as the build one.
40
+
41
+
> Note: If you prefer to run type checking separately from the build process, you can run `npm uninstall fork-ts-checker-webpack-plugin` (or `yarn remove fork-ts-checker-webpack-plugin`) to remove the `fork-ts-checker-webpack-plugin` dependency and then `npx tsc -w` on a new terminal tab.
42
+
43
+
We recommend using [VSCode](https://code.visualstudio.com/) for a better integrated experience.
44
+
45
+
To learn more about TypeScript, check out [its documentation](https://www.typescriptlang.org/).
Copy file name to clipboardexpand all lines: docusaurus/docs/running-tests.md
+3-1
Original file line number
Diff line number
Diff line change
@@ -109,6 +109,8 @@ import Adapter from 'enzyme-adapter-react-16';
109
109
configure({ adapter:newAdapter() });
110
110
```
111
111
112
+
> Note: When using TypeScript with Babel, all your files need to have at least one export, otherwise you will get the error `Cannot compile namespaces when the '--isolatedModules' flag is provided.`. To fix this, you can add `export default undefined` to `src/setupTests.ts`.
113
+
112
114
> Note: Keep in mind that if you decide to "eject" before creating `src/setupTests.js`, the resulting `package.json` file won't contain any reference to it. [Read here](#initializing-test-environment) to learn how to add this after ejecting.
Copy file name to clipboardexpand all lines: docusaurus/docs/setting-up-your-editor.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -120,14 +120,14 @@ Next we add a 'lint-staged' field to the `package.json`, for example:
120
120
// ...
121
121
},
122
122
+ "lint-staged": {
123
-
+ "src/**/*.{js,jsx,json,css}": [
123
+
+ "src/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
124
124
+ "prettier --single-quote --write",
125
125
+ "git add"
126
126
+ ]
127
127
+ },
128
128
"scripts": {
129
129
```
130
130
131
-
Now, whenever you make a commit, Prettier will format the changed files automatically. You can also run `./node_modules/.bin/prettier --single-quote --write "src/**/*.{js,jsx}"` to format your entire project for the first time.
131
+
Now, whenever you make a commit, Prettier will format the changed files automatically. You can also run `./node_modules/.bin/prettier --single-quote --write "src/**/*.{js,jsx,ts,tsx,json,css,scss,md}"` to format your entire project for the first time.
132
132
133
133
Next you might want to integrate Prettier in your favorite editor. Read the section on [Editor Integration](https://prettier.io/docs/en/editors.html) on the Prettier GitHub page.
Copy file name to clipboardexpand all lines: packages/babel-preset-react-app/README.md
+12-9
Original file line number
Diff line number
Diff line change
@@ -32,19 +32,22 @@ Then create a file named `.babelrc` with following contents in the root folder o
32
32
33
33
This preset uses the `useBuiltIns` option with [transform-object-rest-spread](http://babeljs.io/docs/plugins/transform-object-rest-spread/) and [transform-react-jsx](http://babeljs.io/docs/plugins/transform-react-jsx/), which assumes that `Object.assign` is available or polyfilled.
34
34
35
-
## Usage with TypeScript
35
+
## Usage with Flow
36
+
37
+
Flow is enabled by default. Make sure you have a `.flowconfig` file at the root directory. You can also use the `flow` option on `.babelrc`:
To use this package with [`@babel/preset-typescript`](https://www.npmjs.com/package/@babel/preset-typescript), you need to disable `@babel/preset-flow` first.
45
+
## Usage with TypeScript
38
46
39
-
You can achieve this by doing:
47
+
TypeScript is enabled by default. Make sure you have a `tsconfig.json` file at the root directory. You can also use the `typescript` option on `.babelrc`:
0 commit comments