michaelkrone / ngrx-normalizr

Managing normalized state in ngrx applications - transparently
https://michaelkrone.github.io/ngrx-normalizr/
MIT License
50 stars 17 forks source link

NormalizeActionConfig error #32

Closed jaichandra closed 6 years ago

jaichandra commented 6 years ago

Say, I have below schema

import { schema } from 'normalizr';

export class Foo {
    id: string; 
}
// schema
export const fooSchema = new schema.Entity('foo');

And my api call returns a single object.

{
id: '1'
}

when I do a new AddData<Foo>({ data, fooSchema }) in my @Effect, I get below error.

Is this a version problem? I am on @ngrx/store 5.0.0

[ts]
Argument of type '{ data: Foo; fooSchema: Entity; }' is not assignable to parameter of type 'NormalizeActionConfig<Foo>'.
  Object literal may only specify known properties, and 'fooSchema' does not exist in type 'NormalizeActionConfig<Foo>'.
jaichandra commented 6 years ago

The compile time error if fixed by passing data as an array like below:

new AddData<Foo>({ data: [data], schema: fooSchema })

But AddData still doesn't populate the store. I tried SetData as well, but no luck. I added a success action after AddData as per the documentation and that success action is getting called executed. But in my reducer, state.normalized is still null. Please suggest.

jaichandra commented 6 years ago

I got it working. thanks.