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

Custom Static Methods on a Model Class #689

Open
lucasm08 opened this issue Mar 15, 2021 · 0 comments
Open

Custom Static Methods on a Model Class #689

lucasm08 opened this issue Mar 15, 2021 · 0 comments

Comments

@lucasm08
Copy link

Hello, I'm trying to use redux-orm with Typescript, but I ran into an error when I tried use a custom static methods I that I added to a model Class. I'm pretty new to typescript, maybe I'm doing something wrong.

Here are some files

ProductGroup Model:

export class ProductGroup extends Model<typeof ProductGroup, ProductGroupFields> {
    static fields = {
        id: attr(),
        name: attr(),
    };

    static options = {
        idAttribute: "id" as const,
    };

    static parse(productGroupData: GroupFields) {
        return this.upsert(productGroupData);
    }

    toJSON() {
        return { ...this.ref };
    }
}

Usage:

    const session = orm.session(state);

    const {products, contacts} = payload;

    const {ContactGroup,  ProductGroup} = session;


    [ContactGroup, ProductGroup].forEach(modelType => {
        modelType.all().toModelArray().forEach(model => model.delete());
    });

    if(contacts) {
        // tslint:disable-next-line: no-angle-bracket-type-assertion
        contacts.forEach(contact => ContactGroup.parse(contact)); //<------------------- Error. Property 'parse' does not exist on type 'ModelType<ContactGroup>'.
    }

Expectation:
I expect parse to be available on model classes for this Session.

Maybe it's a misuse of typescript, but I would really appreciate if someone can help.

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

1 participant