Bug report
Sandbox link or minimal reproduction code
https://codesandbox.io/p/sandbox/dpzr23
Describe the expected behavior
When using types.compose, I would expect a child's properties to override its parent's properties. This seemed to work fine in previous versions of MST, but it doesn't seem to be the case for the latest version.
Describe the observed behavior
Given the following code:
import { types } from "mobx-state-tree";
enum Invariant {
A = 'A',
B = 'B'
}
const Base = types.model({
name: types.string,
invariant: types.enumeration(Object.values(Invariant))
});
const TypeA = types.compose(Base, types.model('TypeA', {
invariant: Invariant.A
}));
const TypeB = types.compose(Base, types.model('TypeB', {
invariant: types.literal(Invariant.B)
}));
const a = TypeA.create({
name: 'Such a great name'
});
const b = TypeB.create({
name: 'An even better name'
});
I would expect the invariant property to not be required when creating an instance of TypeA or TypeB. However, TypeScript complains and says that the snapshots provided to TypeA.create and TypeB.create are not valid.
Here is the error taken from the codesandbox reproduction:
Argument of type '{ name: string; }' is not assignable to parameter of type 'string | ModelCreationType<{ name: string; invariant: string; }> | undefined'.
Type '{ name: string; }' is not assignable to type 'ModelCreationType<{ name: string; invariant: string; }>'.
Property 'invariant' is missing in type '{ name: string; }' but required in type '{ name: string; invariant: string; }'.typescript(2345)
As I say above, I think this is a regression. However, please let me know if I've missed any recent changes in design decisions or misinterpreted any documentation.
Thanks for a great library! If I have some time I might try look into this, but I'm a bit swamped at the moment.
Bug report
Sandbox link or minimal reproduction code
https://codesandbox.io/p/sandbox/dpzr23
Describe the expected behavior
When using
types.compose, I would expect a child's properties to override its parent's properties. This seemed to work fine in previous versions of MST, but it doesn't seem to be the case for the latest version.Describe the observed behavior
Given the following code:
I would expect the
invariantproperty to not be required when creating an instance ofTypeAorTypeB. However, TypeScript complains and says that the snapshots provided toTypeA.createandTypeB.createare not valid.Here is the error taken from the codesandbox reproduction:
As I say above, I think this is a regression. However, please let me know if I've missed any recent changes in design decisions or misinterpreted any documentation.
Thanks for a great library! If I have some time I might try look into this, but I'm a bit swamped at the moment.