给出TS2322的React-Redux组件:类型“{}”不能分配给类型?

时间:2017-12-19 12:44:05

标签: reactjs typescript redux react-router react-redux

我不确定为什么它会抱怨,因为我很确定我已经正确地连接了所有内容,我的组件类如下:

type SubmitLinkPopupProps =
    SubmitLinkPopupStore.SubmitLinkPopupState
    & typeof SubmitLinkPopupStore.actionCreators
    & RouteComponentProps<{}>;

type SubmitLinkPopupAllProps = SubmitLinkPopupProps;// & InputSubmitLinkProps;

export class SubmitLinkPopup extends Component<SubmitLinkPopupAllProps, SubmitLinkPopupStore.SubmitLinkPopupState>
{

    constructor(props: SubmitLinkPopupAllProps) {
        super(props);
        this.SubmitLink = this.SubmitLink.bind(this);
        this.handleClose = this.handleClose.bind(this);
        this.handleTextFieldChange = this.handleTextFieldChange.bind(this);
    }

    handleOpen = () => {
       //...
    };

    handleClose = () => {
       //...
    };

    handleTextFieldChange(e) {
         //...
    };

    SubmitLink() {
        //...
    }

    public render() {
        //...
    }
}

export default connect((state: Store.RootState) => state.submitLinkPopup, SubmitLinkPopupStore.actionCreators)(SubmitLinkPopup);

和reducer看起来像这样:

export const actionCreators = {
       //...
}

type KnownAction = RequestSubmitLinkAction | CancelSubmitLinkAction;


const submitLinkPopupReducer: Reducer<SubmitLinkPopupState> =
    (state: SubmitLinkPopupState, incomingAction: KnownAction) => {
          //...
    }

    export default submitLinkPopupReducer;

这一切都挂在了商店里:

export interface RootState {
submitLinkPopup: SubmitLinkPopupState
}

const rootReducer = combineReducers({
submitLinkPopup: submitLinkPopupReducer,
})

const rootStore = createStore(
  rootReducer,
  applyMiddleware(middleware),
)

export default rootStore

这是在我之前工作的React-Redux项目中工作的,我不确定导致此问题的配置可能会丢失。

1 个答案:

答案 0 :(得分:1)

根据错误消息,问题是RouteComponentProps<{}>;您需要将其更改为RouteComponentProps<any>