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.
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:
Usage:
Expectation:
I expect
parseto be available on model classes for this Session.Maybe it's a misuse of typescript, but I would really appreciate if someone can help.