我正在生成一个新的反应应用程序
npx create-react-app front-end2 --template typescript
,但没有改变核心,我有这个错误:
类型'{孩子:元素;类名:字符串;}' 不可分配给类型 'DetailedHTMLProps, HTMLDivElement>'。
类型'{孩子:元素;类名:字符串;}' 不可分配给类型 'HTMLAttributes'。
属性“结果”的类型不兼容。
类型 'any[]' 不能分配给类型 'number'。
对于我返回的每个 html 元素。
我的默认 app.tsx:
import React from 'react';
import './App.css';
const App: React.FC = () => {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.tsx</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}
export default App;
我尝试了什么:
-npm install @types/typescript
-npm intall @types/react
-npm intall @prop-types
-delete and re-npm create-react-app...
-npm cache clean --force
- 我在 app.tsx 和 react-app-env.d.ts 中将 jsx 声明为全局
declare global {
namespace JSX {
interface IntrinsicElements {
'my-html-custom-tag': React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>;
}
}
}
package.json 依赖部分:
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.4.0",
"@testing-library/user-event": "^7.2.1",
"@types/jest": "^24.9.0",
"@types/node": "^12.12.25",
"@types/react": "^16.9.17",
"@types/react-dom": "^16.9.5",
"@types/typescript": "^2.0.0",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-scripts": "3.3.0",
"typescript": "^3.7.5"
}
我只是不知道我该怎么做。如果我能给你更多信息,请告诉我,谢谢。