这个ts 类型为什么推断不正确

问题描述

一个TS 高阶 react组件,类型一直提示类型不正确,一直提示这样的错误:

不能将类型“{}”分配给类型“P”。
'{}' is assignable to the constraint of type 'P', but 'P' could be instantiated with a different subtype of constraint 'object'.ts(2322)
图片描述

组件代码

import * as  React from 'react';

interface IProps {
    loading:boolean
}
const withLoader = <P extends object> (Component:React.ComponentType<P>):React.SFC<P & IProps> => 
({loading,...props}:IProps)=>
   loading?(
        <div className="loader-overlay">
            <div className="loader-circle-wrap">
                <div className="loader-circle"/>
            </div>
        </div>
     ):(<Component {...props}/>);


export default withLoader;
阅读 6.1k
1 个回答

原来是这个
![图片描述][1]

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题