2017-03-18 105 views
0

得到错误打字稿反应/终极版

ERROR in [at-loader] ./src/app/components/partials/userPartial.tsx:101:33 TS2339: Property 'level' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<{}, ComponentState>> & { children?: Reac...'.

ERROR in [at-loader] ./src/app/components/partials/userPartial.tsx:102:33 TS2339: Property 'medal' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<{}, ComponentState>> & { children?: Reac...'.

但接口提供

组件在那里我得到错误

<NotificationTypes 
    level={item.level} 
    medal={item.medal} 
    referred={item.user} 
    points={item.points} 
    type={item.type} 
/> 

部件,其中intefaces提供

export interface IPoints { 
    earned: number, 
    total: number 
} 

export interface INotificationTypesProps { 
    level: any, 
    medal: any, 
    points: IPoints, 
    type: number, 
} 

class NotificationTypes extends React.Component<INotificationTypesProps , any> { 
    constructor(props:any){ 
     super(props); 
    } 


    render(){ 

     const { type, level, points, medal} = this.props; 

     switch(type) { 
      case 132: 
       return (
        <span> 
         <Translate value="notification.earned"/> <div 
         className='notify-medal medal-sm-yellow'>{medal}</div> 
        </span> 
       ); 
      case 131: 
       return (
        <span> 
         <Translate value="notification.received"/> {points.earned} <Translate 
         value="notification.pointScored"/> 
         &nbsp;{points.total} <Translate value="notification.points"/> 
        </span> 
       ); 
      default: 
       return <div /> 
     } 
    } 
} 

const mapStateToProps = (state) => { 
    return { 
     _CONFIG: state._CONFIG.CDN.static_uri, 
    }; 
}; 
export default connect(mapStateToProps, null)(NotificationTypes); 

如何解决这个矛盾呢? 我也有类似的错误,也有很少的组件 为什么它没有按预期工作?

希望你的帮助!

回答

2

我的猜测是,当你使用你使用这个NotificationTypes组件:

export default connect(mapStateToProps, null)(NotificationTypes); 

react-dedux定义文件似乎连接功能有两个签名。
The first是不通用的,返回InferableComponentDecorator

export declare function connect(): InferableComponentDecorator; 

the second是通用的,可以用于返回通用ComponentDecorator

export declare function connect<TStateProps, TDispatchProps, TOwnProps>(
    mapStateToProps?: FuncOrSelf<MapStateToProps<TStateProps, TOwnProps>>, 
    mapDispatchToProps?: FuncOrSelf<MapDispatchToPropsFunction<TDispatchProps, TOwnProps> | MapDispatchToPropsObject>, 
    mergeProps?: MergeProps<TStateProps, TDispatchProps, TOwnProps>, 
    options?: Options 
): ComponentDecorator<TStateProps & TDispatchProps, TOwnProps>; 

我还没有使用它,但你或许应该做类似的事情:

export default connect<typeof mapStateToProps, {}, INotificationTypesProps >(mapStateToProps, null)(NotificationTypes);