Type, that fallbacks null | undefined
to []
#1868
-
How to make a type, that fallbacks |
Beta Was this translation helpful? Give feedback.
Answered by
EmilTholin
Feb 1, 2022
Replies: 1 comment
-
Hi @haalogen!
Example import { types } from "mobx-state-tree";
const Type = types.array(types.string);
const OtherType = types.model({
type: types.optional(Type, [], [undefined, null])
});
const otherType = OtherType.create({
type: null
});
console.log(otherType.type); // [] |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
EmilTholin
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @haalogen!
types.optional
has a third optional argumentoptionalValues
that you can use to specify what values you want to override with thedefaultValue
.Example