Typescript 在RealmJS中使用undefined而不是null

Typescript 在RealmJS中使用undefined而不是null,typescript,react-native,realm,Typescript,React Native,Realm,我想知道是否有办法强制RealmJS在可选字段上返回undefined,而不是null 我这样问是因为typescript的可选类型实际上是T | undefined,而不是T | null。我不想混淆未定义和空 谢谢。所有字段都是在模式中定义的,当您定义了某个字段存在时,无论它是否有值,都不可能说它是未定义的。如果说可选字段是null而不是undefined,则更有意义,因为undefined意味着可选字段甚至不存在。您可以直接在模式中执行此操作。 例如: const OrderSchema

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

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


谢谢。

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

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

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