gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 11:32:43 28 4
gpt4 key购买 nike

我决定在 TypeScript 中使用 React JS。做一个简单的hello world项目。引用两本书,他们都提出了以下建议。全新的项目,而不是升级或任何这些场景。新鲜开始。

npx create-react-app try-react -–template typescript
这很好用。
但是,这些文件仍然具有 .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.
所以,我删除了全局安装。再试一次。
一样。没有带有 .tsx 扩展名的文件。本书作者没有提及必须手动重命名这些文件的任何内容。
所以,我的问题是,
  • 模板不应该自动将所有扩展名设置为 .tsx 吗?
  • 这样做的唯一方法是手动从 .js 更改为 .tsx 吗?
  • 我们是否总是这样做,这确实是常态。也许,本书作者确实手动完成了但忘记将其包含在说明中?
  • 最佳答案

    我有同样的问题。什么为我解决了:npm install cra-template-typescript出于某种原因,模板不适合我。

    关于reactjs - create-react-app with --template typescript 不创建 .tsx 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65505209/

    28 4 0