Jay*_*Jay 6 typescript reactjs
我决定在 TypeScript 中使用 React JS。做一个简单的hello world项目。参考两本书,他们都提出了以下建议。全新的项目,而不是升级或任何这些场景。新鲜开始。
npx create-react-app try-react -–template typescript
Run Code Online (Sandbox Code Playgroud)
这很好用。
但是,这些文件仍然具有 .js 扩展名。在书中,其中一个有截图,它已经带有 .tsx 扩展名。
我看过这个链接,https://create-react-app.dev/docs/adding-typescript/。它说,
If you've previously installed create-react-app globally via npm install -g create-react-app, we recommend you uninstall the package using npm uninstall -g create-react-app or yarn global remove create-react-app to ensure that npx always uses the latest version.
Global installs of create-react-app are no longer supported.
Run Code Online (Sandbox Code Playgroud)
所以,我删除了全局安装。再试一次。
一样。没有带有 .tsx 扩展名的文件。本书作者没有提及必须手动重命名这些文件的任何内容。
所以,我的问题是,
小智 5
就我而言,解决问题的方法是全局安装打字稿模板
npm install -g cra-template-typescript
Run Code Online (Sandbox Code Playgroud)
一旦我这样做了,我就跑了
npx create-react-app client-app --template typescript
Run Code Online (Sandbox Code Playgroud)
蚂蚁成功了。.tsx的所有脚本文件
| 归档时间: |
|
| 查看次数: |
546 次 |
| 最近记录: |