首页 > 解决方案 > 领域:“数组”类型的属性“虚拟”不能为空

问题描述

我正在尝试使用这些模式打开一个领域连接。

[{
    name: 'Day',
    properties: {
        day: {type: 'int', optional: true},
        time: {type: 'string', optional: true},
    }
},
{
    name: 'Period',
    properties: {
        close: {type: 'Day', optional: true},
        open: {type: 'Day', optional: true}
    }
},
{
    name: 'Dummy',
    properties: {
        isDummy: {type: 'bool', optional: true},
        periods: {type: 'Period[]', optional: true},
    }
}]

我得到这个错误:Property "Dummy" of type 'array' cannot be nullable

我不知道为什么会收到此错误。如果有人可以向我解释这一点,我将不胜感激。

标签: react-nativerealm

解决方案


您应该像这样 [] 将默认值设置为空列表,因为您想要空数组。所以你应该使用这个:

{
    name: 'Period',
    properties: {
        close: {type: 'Day[]', default: []}, // <-- change here
        .....
    }
}

代替:

{
    name: 'Period',
    properties: {
       close: {type: 'Day', optional: true},
       open: {type: 'Day', optional: true}
    }
}

推荐阅读