-
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. |
Beta Was this translation helpful? Give feedback.
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 |
Beta Was this translation helpful? Give feedback.
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.model
describes 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.…