diff --git a/packages/realm/src/Object.ts b/packages/realm/src/Object.ts index 6851b1b01a..1d7c479f62 100644 --- a/packages/realm/src/Object.ts +++ b/packages/realm/src/Object.ts @@ -31,6 +31,7 @@ import { OrderedCollection, Realm, RealmObjectConstructor, + RequirableProperties, Results, TypeAssertionError, TypeHelpers, @@ -152,7 +153,7 @@ const PROXY_HANDLER: ProxyHandler> = { * properties not specified will be optional, and will default to a sensible * null value if no default is specified elsewhere. */ -export class RealmObject = never> { +export class RealmObject = never> { /** * This property is stored on the per class prototype when transforming the schema. * @internal diff --git a/packages/realm/src/Unmanaged.ts b/packages/realm/src/Unmanaged.ts index 3d01ce22e1..081df238ba 100644 --- a/packages/realm/src/Unmanaged.ts +++ b/packages/realm/src/Unmanaged.ts @@ -61,9 +61,13 @@ type RealmSetRemappedModelPart = { /** * Exchanges properties defined as a {@link Counter} with a `number`. */ -type RealmCounterRemappedModelPart = { - [K in ExtractPropertyNamesOfTypeExcludingNullability]?: Counter | number | Exclude; -}; +type RealmCounterRemappedModelPart> = OptionalExceptRequired]: Counter | number | Exclude; +}, RequiredProperties>; + +type RealmObjectRemappedModelPart> = OptionalExceptRequired>]: Unmanaged | undefined | null; +}, RequiredProperties>; /** Omits all properties of a model which are not defined by the schema */ export type OmittedRealmTypes = Omit< @@ -74,33 +78,39 @@ export type OmittedRealmTypes = Omit< | ExtractPropertyNamesOfType | ExtractPropertyNamesOfType | ExtractPropertyNamesOfTypeExcludingNullability + | ExtractPropertyNamesOfTypeExcludingNullability> >; -/** Make all fields optional except those specified in K */ -type OptionalExcept = Partial & Pick; +export type RequirableProperties = Omit; + +/** Make all fields optional except those specified in RequiredProperties */ +type OptionalExceptRequired> = Partial & Pick; /** * Omits all properties of a model which are not defined by the schema, * making all properties optional except those specified in RequiredProperties. */ -type OmittedRealmTypesWithRequired> = OptionalExcept< +type OmittedRealmTypesWithRequired> = OptionalExceptRequired< + T, OmittedRealmTypes, RequiredProperties >; /** Remaps realm types to "simpler" types (arrays and objects) */ -type RemappedRealmTypes = RealmListRemappedModelPart & - RealmDictionaryRemappedModelPart & - RealmSetRemappedModelPart & - RealmCounterRemappedModelPart; +type RemappedRealmTypes> = + & RealmListRemappedModelPart + & RealmDictionaryRemappedModelPart + & RealmSetRemappedModelPart + & RealmCounterRemappedModelPart + & RealmObjectRemappedModelPart; /** * Joins `T` stripped of all keys which value extends {@link Collection} and all inherited from {@link Realm.Object}, * with only the keys which value extends {@link List}, remapped as {@link Array}. All properties are optional * except those specified in `RequiredProperties`. */ -export type Unmanaged = never> = OmittedRealmTypesWithRequired< +export type Unmanaged = never> = OmittedRealmTypesWithRequired< T, RequiredProperties > & - RemappedRealmTypes; + RemappedRealmTypes; \ No newline at end of file