打字稿反应/减少

时间:2017-03-18 21:37:07

标签: javascript reactjs typescript redux

获取错误

>>> re.sub(r'<<({})>>'.format("|".join(sorted(dico.keys(), reverse=True))), lambda x: dico[x.group(1)], teststr)

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}
/>

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

希望你的帮助!

1 个答案:

答案 0 :(得分: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);