我正在将一个只有React的应用程序转换为Typescript,这是我的新手。因此,这是react + typescript中的一个更高阶的组件,我想使用prop-types,代码:
interface GuestRouteProps {
isAuthenticated: boolean;
component: new (props: any) => React.Component; // is this right?
}
const GuestRoute: React.SFC<GuestRouteProps> = ({ // error on GuestRoute
isAuthenticated,
component: Component,
...rest
}) => (
<Route
{...rest}
render={props =>
!isAuthenticated ? <Component {...props} /> : <Redirect to='/' />
}
/>
);
GuestRoute.propTypes = { // <-- the error is underlined here, works if no typescript
component: PropTypes.func.isRequired,
isAuthenticated: PropTypes.bool.isRequired
};
我收到错误消息,指出“属性'组件'的类型不兼容”。