How to store Typescript data types in RxDB?

366 views Asked by At

New to RxDB here.

I've read through the RxDB document and seems there's no elegant way to store types in RxDB. For example,

  1. Sum types
type Animal = {kind: 'horse', pawColor: Color} | {kind: 'bird', speed: number}
  1. Simple OR types (or enums):
type User = {ClientStatus: ClientStatus}
type ClientStatus = 'ONLINE'|'OFFLINE'

If I understand correctly, since the RxDB schema is similar to json-schema, we can think of the RxDB documents as raw json, therefore the serialization/deserialization from/to our Typescript types are own our own.

Is this assumption correct? Or am I missing some RxDB tooling that can help us?

1

There are 1 answers

0
pubkey On

Your assumtion is not correct. For example you can use enum types in JsonSchema and also in RxDB https://json-schema.org/understanding-json-schema/reference/generic.html#enumerated-values