Skip to content

Commit e0939b6

Browse files
committed
Automatically create a tsconfig.json when entrypoint is TypeScript
1 parent 680cf93 commit e0939b6

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

docusaurus/docs/adding-typescript.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ To add TypeScript to a Create React App project, follow these steps:
1111

1212
1. Run `npm install --save typescript @types/react @types/react-dom @types/jest` (or `yarn add typescript @types/react @types/react-dom @types/jest`).
1313
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-
3. Create a [`tsconfig.json` file](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) at the root directory with `{}` in it.
14+
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`.
1515
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).
1616

1717
Type errors will show up in the same console as the build one.

packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ function writeJson(fileName, object) {
2121

2222
function verifyTypeScriptSetup() {
2323
if (!fs.existsSync(paths.appTsConfig)) {
24-
return;
24+
if (!paths.appIndexJs.match(/\.ts?$/)) {
25+
return;
26+
}
27+
writeJson(paths.appTsConfig, {});
2528
}
2629

2730
const isYarn = fs.existsSync(paths.yarnLockFile);

0 commit comments

Comments
 (0)