create-react-app with --template typescript 不创建 .tsx 文件

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 扩展名的文件。本书作者没有提及必须手动重命名这些文件的任何内容。

所以,我的问题是,

  1. 模板不应该自动将所有扩展名设置为 .tsx 吗?
  2. 这样做的唯一方法是手动从 .js 更改为 .tsx 吗?
  3. 我们是否总是这样做,这确实是常态。也许,本书作者确实手动完成了但忘记将其包含在说明中?

Ale*_*yny 5

我有同样的问题。是什么为我解决了这个问题:

npm install cra-template-typescript

由于某种原因,该模板不适合我。


小智 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的所有脚本文件