我正在尝试创建一个具有可选的可为空字符串值的模型。 我试过两者都用
hint: types.optional(types.string, ""),
和
hint: types.maybe(types.string),
当我尝试将 json 对象设置为对象时,两者都会导致错误。 如果我手动循环遍历 json 对象并将空内容设置为空字符串“”,则可以工作。
Error while converting "jsoncontent" at path "content" value
null
is not assignable to type:string
(Value is not a string).
最佳答案
您可以使用 types.maybeNull
拥有一个也可以是 null
的类型。
hint: types.maybeNull(types.string)
关于javascript - 如何在 Mobx-State-Tree 中拥有可为空的字符串值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51840640/