1.创建react-ts项目,使用如下命令行创建
npx create-react-app my-app-ts --template typescript
2.熟悉大致的配置文件tsconfig.json
{
"compilerOptions": {
"noImplicitAny": false,//不需要显示的声明变量any
"target": "es5",//编译后的目标版本
"lib": [//这个是表示编译期间要包含进来的库
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,//允许混合编写js文件
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",//配置代码系统模块,比如node.js
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,//编译器将每个文件单独编译成模块
"noEmit": true,
"jsx": "react-jsx"//允许编译器支持react-jsx
},
"include": [
"src"
]
}