JavaScriptReactTypeScript

Migrate Create React App from JavaScript to TypeScript by using ts-migrate

ts-migrate is a Node.js tools to convert from JavaScript to TypeScript. We can easy to migrate your React appl […]

広告ここから
広告ここまで

ts-migrate is a Node.js tools to convert from JavaScript to TypeScript.

We can easy to migrate your React application written by JavaScript to use it.

Prepare

In Create React App, we need to get the following files to use TypeScript.

  • tsconfig.json
  • src/react-app-env.d.ts

We can easy to get creating a new dummy React app.

$ npx create-react-app test --typescript
$ mv test/tsconfig.json ./
$ mv test/src/react-app-env.d.ts ./src

Installing npm packages for TypeScript

At least, we need add these packages.

$ npm i -D @types/react @types/react-dom @types/node @types/jest typescript

Run ts-migrate

Using ts-migrate, we can rename all js/jsx files to ts/tsx.

$ npx ts-migrate rename ./

And update all code to be able to run in TypeScript.

$ npx ts-migrate migrate ./

Fix errors of TypeScript

Depends on any dev tools like prop-types, sometimes, ts-migrate will remain any TS errors.

We should run npm run build and fix all errors.

ブックマークや限定記事(予定)など

WP Kyotoサポーター募集中

WordPressやフロントエンドアプリのホスティング、Algolia・AWSなどのサービス利用料を支援する「WP Kyotoサポーター」を募集しています。
月額または年額の有料プランを契約すると、ブックマーク機能などのサポーター限定機能がご利用いただけます。

14日間のトライアルも用意しておりますので、「このサイトよく見るな」という方はぜひご検討ください。

広告ここから
広告ここまで

Related Category posts