还可以通过将 tsconfig.json 文件添加到项目中来使用带有 create-react-app 的装饰器,这意味着启用对 typescript 的支持。
您需要将 experimentalDecorators 设置为 true in tsconfig.json 的编译器选项
希望我们知道 .js 和 .tsx 文件可以共存,所以无论我们想要使用装饰器的哪个文件,我们都可以转换为 .tsx 其余文件可以保留 .js 文件
{
"compilerOptions": {
"target": "esnext",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react",
"noImplicitThis": false,
"experimentalDecorators": true, //<----
"types": ["cypress"]
},
"include": ["src"]
}