Avatar ·

TypeScript和React中的错误“JSX元素类型'...'没有任何构造或调用签名”

大家好!我是TypeScript和React的新手,已经为这个错误折腾了好几个小时。我写了一个简单的组件,应该渲染用户列表,但TypeScript报错了。 这是我的代码: ```tsx // UserList.tsx import React from 'react'; interface User { id: number; name: string; } const UserItem: React.FC = ({ name }) => { return
  • {name}
  • ; }; // 组件,接受用户数组 function UserList({ users }: { users: User[] }) { return (
      {users.map(user => ( ))}
    ); } export default UserList; ``` 但是当我尝试在App.tsx中使用这个组件时,TypeScript报错: ``` JSX element type 'UserItem' does not have any construct or call signatures. ``` 我已经尝试了不同的方法:添加了`React.FC`,去掉了它,更改了props类型——都没用。我哪里做错了?为什么TypeScript认为我的