reactjs - อาร์กิวเมนต์ของประเภท 'xxxx' ไม่สามารถกำหนดให้กับพารามิเตอร์ของประเภท 'JSXElementConstructor' ได้
ฉันกำลังเรียนหลักสูตร TypeScript บน Udemy ลิงก์
import { connect } from 'react-redux';
import { Todo, fetchTodos } from '../actions';
import { StoreState } from '../reducers';
interface AppProps {
todos: Todo[];
fetchTodos(): any;
}
class _App extends React.Component<AppProps> {
render() {
return <div>Hi there!</div>;
}
}
const mapStateToProps = ({ todos }: StoreState): { todos: Todo[] } => {
return { todos };
};
export const App = connect(
mapStateToProps,
{ fetchTodos }
)(_App);
อย่างไรก็ตาม ข้อผิดพลาดนี้ปรากฏขึ้น:
Argument of type 'typeof _App' is not assignable to parameter of type 'JSXElementConstructor<never>'.
Type 'typeof _App' is not assignable to type 'new (props: never) => Component<any, any, any>'.
Construct signature return types '_App' and 'Component<any, any, any>' are incompatible.
The types of 'refs' are incompatible between these types.
Type '{ [key: string]: React.ReactInstance; }' is not assignable to type '{ [key: string]: import("C:/Users/xxxxxxxxxxxxx/271-connecting/rrts/node_modules/@types/react-redux/node_modul
es/@types/react/index").ReactInstance; }'.
'string' index signatures are incompatible.
Node'.
Type '{}' is not assignable to type 'ReactNode'. TS2345
ขอทราบวิธีแก้ปัญหานี้ได้ไหม?.....................................
ฉันคิดว่าฟังก์ชันที่ส่งกลับโดย connect( mapStateToProps, { fetchTodos } ) สมมติว่าอาร์กิวเมนต์เป็นคอมโพเนนต์ React ที่ไม่รับ props ใด ๆ ใช่ไหม?
คำตอบ #1
นี่คือปัญหาเกี่ยวกับเวอร์ชันเมื่อคุณพยายามย้ายจากเวอร์ชัน React เก่าไปยังเวอร์ชันที่อัปเดต กรุณาอัปเดตไลบรารีด้านล่าง
yarn add react-redux
yarn add @types/react-redux
