Skip to content

TypeScript and union #1906

May 10, 2022 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

I edited my original post thus ⬇️, light of #1907

const Foo = types.model({id: types.identifier, foo: types.string, type: "foo"});
const Bar = types.model({id: types.identifier, bar: types.number, type: "bar"});

const Foo = types.model({id: types.identifier, foo: types.string, type: types.literal("foo")});
const Bar = types.model({id: types.identifier, bar: types.number, type: types.literal("bar")});


I'm now able to answer my question:

How does this magic work?

By 'guessing' the first model which appears to match the snapshot:

return this._types
.filter((t) => t !== re…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@coolsoftwaretyler
Comment options

Answer selected by coolsoftwaretyler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants