Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

State with genericity #52

Open
ThomasMerant opened this issue Jun 16, 2020 · 1 comment
Open

State with genericity #52

ThomasMerant opened this issue Jun 16, 2020 · 1 comment

Comments

@ThomasMerant
Copy link

Hello, I would like to create standard Reducer like this :

import { ImmerReducer } from "immer-reducer";

interface HttpListResult<T> {
    query: HttpListQuery;
    total?: number;
    data?: T[];
}

interface ListViewState<T> extends HttpListResult<T> {
    isLoading?: boolean;
}

export abstract class MyReducerBase<T> extends ImmerReducer<ListViewState<T>> {
    getAll(query: HttpListQuery) {
        this.draftState = {
            query,
            isLoading: true,
        };
    }

    getAllResult(result: HttpListResult<T>) {
        this.draftState = {
            ...result,
            isLoading: false,
        };
    }
}

But in the draftState, data property is typed in Draft<T>...

What is my error ?

@yrral86
Copy link

yrral86 commented Oct 1, 2020

With typescript 3.8 I see no type errors with your code, but I don't know what your type definition is for HttpListQuery.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants