【问题标题】:Use undefined instead of null in RealmJS在 RealmJS 中使用 undefined 而不是 null
【发布时间】:2019-11-20 05:34:51
【问题描述】:

我想知道是否有办法强制 RealmJS 在可选字段上返回 undefined 而不是 null

我问这个,因为 typescript 的可选类型实际上是 T | undefined,而不是 T | null。我不想混淆undefinednull

谢谢。

【问题讨论】:

    标签: typescript react-native realm


    【解决方案1】:

    所有字段都在模式中定义,当您定义它存在时,无论它是否具有值,都无法说它是未定义的。说可选字段是 null 而不是 undefined 更有意义,因为 undefined 意味着可选字段甚至不存在。

    【讨论】:

      【解决方案2】:

      您可以直接在架构中执行此操作。
      例如:

      const OrderSchema = {
        name: 'Order',
        primaryKey: 'id',
        properties: {
          id: 'int',
          table: { type: 'int', optional: true, default: null },
        }
      }
      

      【讨论】:

        猜你喜欢
        • 2020-11-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-02-15
        相关资源
        最近更新 更多