mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-03-28 07:58:04 +08:00
Automatically create a tsconfig.json when entrypoint is TypeScript
This commit is contained in:
@@ -11,7 +11,7 @@ To add TypeScript to a Create React App project, follow these steps:
|
||||
|
||||
1. Run `npm install --save typescript @types/react @types/react-dom @types/jest` (or `yarn add typescript @types/react @types/react-dom @types/jest`).
|
||||
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`).
|
||||
3. Create a [`tsconfig.json` file](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) at the root directory with `{}` in it.
|
||||
3. Create a [`tsconfig.json` file](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) at the root directory with `{}` in it. Alternatively, rename `index.js` to `index.tsx`.
|
||||
4. Restart your development server (if applicable). This will set sensible defaults and the required values in your [`tsconfig.json` file](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html).
|
||||
|
||||
Type errors will show up in the same console as the build one.
|
||||
|
||||
@@ -21,7 +21,10 @@ function writeJson(fileName, object) {
|
||||
|
||||
function verifyTypeScriptSetup() {
|
||||
if (!fs.existsSync(paths.appTsConfig)) {
|
||||
return;
|
||||
if (!paths.appIndexJs.match(/\.ts?$/)) {
|
||||
return;
|
||||
}
|
||||
writeJson(paths.appTsConfig, {});
|
||||
}
|
||||
|
||||
const isYarn = fs.existsSync(paths.yarnLockFile);
|
||||
|
||||
Reference in New Issue
Block a user