|
So this simple code: type Foo = {
foo: string
}
const MyModelFoo = types.model<Foo>('Foo', {
foo: types.string,
})triggers the following error: What I do wrong? This looks like a bug. |
Answered by
thegedge
Jan 7, 2025
Replies: 1 comment 8 replies
|
The typing here is probably a bit confusing, but I'd recommend using your type for instances, not the model itself: The problem in your example is that the generic argument for In general I'd recommend always letting TypeScript derive the generic arguments for |
8 replies
Answer selected by
coolsoftwaretyler
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment



The typing here is probably a bit confusing, but I'd recommend using your type for instances, not the model itself:
The problem in your example is that the generic argument for
types.modeldescribes the structure of the properties and not the instance.{ foo: types.string }does not match{ foo: string }, hence the error you're seeing. It would match{ foo: "abc" }, which would actually be the same as{ foo: types.optional(types.string, "abc") }.In general I'd recommend always letting TypeScript derive the generic arguments for
types.…