网页 综合 更新时间 2026-10-19 15:33:02

TypeScript Setup | RxDB

自动蜘蛛 rxdb.info 正文约 1230 字
TypeScript Setup | RxDB
In this tutorial you will learn how to use RxDB with TypeScript. We will create a basic database with one collection and several ORM-methods, fully typed!
RxDB directly comes with its typings and you do not have to install anything else. The latest version of RxDB requires TypeScript v3.8 or newer. All types are exported from rxdb, see the import reference for the full list of type and plugin imports. How to type a replication is shown in using the replication with TypeScript. Our way to go is
First you import the types from RxDB.
First we have to define the TypeScript type of the documents of a collection:
Option A: Create the document type from the schema
Option B: Manually type the document type
Option C: Generate the document type from schema during build time
If your schema is in a .json file or generated from somewhere else, you might generate the typings with the json-schema-to-typescript module.
We also add some ORM-methods for the document.
We can merge these into our TodoDocument.
Now we can define type for the collection which contains the documents.
Before we can define the database, we make a helper-type which contains all collections of it.
Now that we have declared all our types, we can use them.
访问原文 返回搜索 https://rxdb.info/tutorials/typescript.html
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。