简体   繁体   English

现有 React 项目中的 Typescript

[英]Typescript in Existing React Project

My question is based on installing typescript in existing React project.我的问题是基于在现有的 React 项目中安装 typescript 。 It is not related to how to create typescript react它与如何创建 typescript 反应无关

I have cloned a repo from AWS where there is a react app.我已经从 AWS 克隆了一个 repo,其中有一个 react 应用程序。 Now, I need to make an app using typescript.现在,我需要使用 typescript 制作一个应用程序。 To install the typescript in React I have run a command "npm install --save typescript @types/node @types/react @types/react-dom @types/jest".要在 React 中安装 typescript,我运行了一个命令“npm install --save typescript @types/node @types/react @types/react-dom @types/jest”。 It is creating typescript in package.json but not creating tsconfig.json file.它正在 package.json 中创建 typescript 但不创建 tsconfig.Z466DEEC76ECDF2446D38571F63 文件。

My other question is should index.ts file created automatically in React and if it is then how could I convert into lib/index.js within React.我的另一个问题是应该在 React 中自动创建 index.ts 文件,如果是,那么我如何在 React 中转换为 lib/index.js。

这是当前的 React 文件结构

Please consider the article linked in the comments of the post as a guide for migrating from JSreact to TSreact.请考虑将帖子评论中链接的文章作为从 JSreact 迁移到 TSreact 的指南。

For a simple answer, the command below will init a tsconfig.json file with npm as a manager.对于一个简单的答案,下面的命令将初始化一个tsconfig.json文件,其中 npm 作为管理器。

npx tsc --init

for yarn用于纱线

yarn tsc --init

(for completeness). (为了完整性)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM