ice-lab / icestore

🌲 Simple and friendly state for React
MIT License
397 stars 35 forks source link

dispatch typings #112

Closed avalanche1 closed 4 years ago

avalanche1 commented 4 years ago

How can I type annotate dispatch here?: image icestore doesnt export RootDispatch type.

imsobear commented 4 years ago

src/store.ts export RootDispatch:

// src/store.ts
import { createStore, IcestoreRootState, IcestoreDispatch } from '@ice/store';
import models from './models';

const store = createStore(models);

export default store;
export type Models = typeof models;
export type Store = typeof store;
export type RootDispatch = IcestoreDispatch<Models>;
export type RootState = IcestoreRootState<Models>;
// models/todo.ts
import { RootDispatch } from '../store';

And we will update the docs.

avalanche1 commented 4 years ago

image image image

imsobear commented 4 years ago

@alvinhui

alvinhui commented 4 years ago

see: https://codesandbox.io/s/github/ice-lab/icestore/tree/master/examples/todos?module=/src/index.tsx&file=/src/models/index.ts

you must add interface to avoid recursive type checking.