When initializing a store and defining the initial state in the constructor, that initial store is not produced by immer and thus not immutable until a state change has been performed.
interface TestState {
test: string;
}
@Injectable({ providedIn: 'root' })
export class TestStore extends ImmerComponentStore<TestState> {
constructor() {
super({ test: 'foo' });
this.get().test = 'bar'; // should throw an error but does not
}
}
Replacing the defaultState in the super call by a produced value correctly causes an error to be thrown.
When initializing a store and defining the initial state in the constructor, that initial store is not produced by immer and thus not immutable until a state change has been performed.
Replacing the defaultState in the
super
call by a produced value correctly causes an error to be thrown.