Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 如何在react typescript中设置HOC中的道具类型?_Reactjs_Typescript_Higher Order Components - Fatal编程技术网

Reactjs 如何在react typescript中设置HOC中的道具类型?

Reactjs 如何在react typescript中设置HOC中的道具类型?,reactjs,typescript,higher-order-components,Reactjs,Typescript,Higher Order Components,我有一个简单的withAuth HOC。我正在尝试定义道具的类型 const withAuth = (Component: typeof React.Component) => (role: string) => { return (props) => { const { data, loading } = useGetUser(); if (loading) { return <p>Loading...</p>;

我有一个简单的withAuth HOC。我正在尝试定义道具的类型

const withAuth = (Component: typeof React.Component) => (role: string) => {
  return (props) => {
    const { data, loading } = useGetUser();
    if (loading) {
      return <p>Loading...</p>;
    }

    if (!data) {
      return <Redirect ssr to="/api/v1/login" />;
    } else {
      if (role && !isAuthorized(data, role)) {
        return <Redirect ssr to="/api/v1/login" />;
      }

      return <Component user={data} loading={loading} {...props} />;
    }
  };
};
给你:


从“React”导入React,{FC}
类型道具={
名称:string
}
常数A:FC=()=>
const withAuth=(组件:React.ComponentType

)=>(角色:字符串)=>{ 返回(道具:P)=>{ 返回; } }; const result1=withAuth(A)('hello')({label:'hello'})//错误 const result2=withAuth(A)('hello')({name:'hello'})//确定

这里有:


从“React”导入React,{FC}
类型道具={
名称:string
}
常数A:FC=()=>
const withAuth=(组件:React.ComponentType

)=>(角色:字符串)=>{ 返回(道具:P)=>{ 返回; } }; const result1=withAuth(A)('hello')({label:'hello'})//错误 const result2=withAuth(A)('hello')({name:'hello'})//确定

Try
constwithauth=(组件:React.ReactNode)
?Try
constwithauth=(组件:React.ReactNode)
React.Component<T>
  Component: typeof React.Component<T> // Parameter '(Missing)' implicitly has an 'any' type.

 props:T // Cannot find name 'T'