Skip to content

Commit

Permalink
example(rematch-tsx): fix type errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Mar 12, 2021
1 parent f2a4433 commit 0431042
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
6 changes: 4 additions & 2 deletions example/rematch-tsx/src/models/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { init, RematchRootState, RematchDispatch, Models } from '@rematch/core';
import loadingPlugin, { ExtraModelsFromLoading } from "@rematch/loading";
import loadingPlugin, { ExtraModelsFromLoading } from '@rematch/loading';
import global from './global';
import login from './login';

Expand All @@ -10,7 +10,7 @@ export interface RootModel extends Models<RootModel>, FullModel {

type FullModel = ExtraModelsFromLoading<RootModel>;

export const models: RootModel = { global } as RootModel;
export const models = { global } as RootModel;
export const store = init<RootModel, FullModel>({
models,
plugins: [loadingPlugin()],
Expand All @@ -19,5 +19,7 @@ export const store = init<RootModel, FullModel>({
export const { dispatch } = store;

export type Store = typeof store;
// export type Dispatch = RootModel;
// export type Dispatch = ReduxDispatch<RootModel>;
export type Dispatch = RematchDispatch<RootModel>;
export type RootState = RematchRootState<RootModel>;
7 changes: 4 additions & 3 deletions example/rematch-tsx/src/pages/login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ const mapState = ({ login, loading }: RootState) => ({
account: login.userData,
});

const mapDispatch = (dispatch: Dispatch) => ({
const mapDispatch: any = (dispatch: Dispatch) => ({
submit: dispatch.login.submit,
});

type connectedProps = ReturnType<typeof mapState> & ReturnType<typeof mapDispatch>;
type Props = connectedProps & DefaultProps;
type StateProps = ReturnType<typeof mapState>;
type DispatchProps = ReturnType<typeof mapDispatch>;
type Props = StateProps & DispatchProps & DefaultProps;

function Login(props: Props) {
const { loading } = props;
Expand Down
13 changes: 7 additions & 6 deletions example/rematch-tsx/src/routes/Controller.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@ import React from 'react';
import { Switch, Route } from 'react-router-dom';
import { connect } from 'react-redux';
import { Dispatch, RootState } from '../models';
import { getRouterData } from '../routes/router';

type connectedProps = ReturnType<typeof mapState> & ReturnType<typeof mapDispatch>;
type Props = connectedProps &
typeof Controller.defaultProps & {
routerData: any;
type StateProps = ReturnType<typeof mapState>;
type DispatchProps = ReturnType<typeof mapDispatch>;
type Props = StateProps &
DispatchProps & {
routerData: typeof getRouterData;
};

const mapState = ({ global }: RootState) => ({
// token: global.token,
// userData: global.userData,
});

const mapDispatch = (dispatch: Dispatch) => ({
const mapDispatch: any = (dispatch: Dispatch) => ({
// verify: dispatch.global.verify,
// verify: global.verify,
});

class Controller extends React.PureComponent<Props> {
static defaultProps = {};
componentDidMount() {
// this.props.verify();
}
Expand Down

0 comments on commit 0431042

Please sign in to comment.