我有一个现有的react应用程序,我用Vite创建了它。我在Vite中使用了反应模板-
yarn create vite my-react-app --template react随着项目的进展,将TypeScript纳入更严格的类型检查似乎是个好主意。我之前在一个现有的项目中加入了TypeScript,在这个清晰的文档的帮助下,我使用了create app。我尝试在我的Vite应用程序中加入同样的功能。我在我的终端上执行了以下代码-
yarn add typescript @types/node @types/react @types/react-dom @types/jest我将.jsx文件重命名为.tsx,将vite.config.js重命名为vite.config.ts,并重新启动vite服务器。
但令我十分沮丧的是,这个应用程序停止了工作。我在vite文档中找不到任何将TypeScript添加到现有应用程序的文档。我还在Vite Github社区里搜索,但在那里找不到任何相关的东西。我在网上也找不到任何与此相关的东西。大部分内容都在CRA和打字本上。
如能对此提供任何帮助,将不胜感激。谢谢!
发布于 2022-08-30 12:31:16
您只需要添加类型记录和tsconfig.json文件
和
npm install typescript
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"isolatedModules": true,
"noEmit": true
}
}
默认情况下,Vite支持ts
发布于 2022-08-09 22:41:20
您可以使用以下方法创建ViteJS + React + TS项目:
yarn create vite my-react-app --template react-tshttps://stackoverflow.com/questions/70991689
复制相似问题