Я впервые использую RxDB, и я столкнулся со странной ошибкой Typescript.
Соответствующие части моего проекта Electron следующие:
import RxDB, { RxCollection, RxDatabase } from "rxdb";
RxDB.plugin(require("pouchdb-adapter-idb"));
// Took this from the Electron example on Github so I knew I had a valid JSONSchema
const heroSchema = {
title: 'hero schema',
description: 'describes a simple hero',
version: 0,
type: 'object',
properties: {
name: {
type: 'string',
primary: true
},
color: {
type: 'string'
}
},
required: ['color']
};
// These lines are actually in an async function so the await keyword is not an issue
const db = await RxDB.create({ name: "heroedb", adapter: "idb" });
const devices = await db.collection({
name: "herocollection",
schema: heroSchema
});
Но Typescript жалуется:
Argument of type '{ name: string; schema: { title: string; description: string; version: number; type: string; prop...' is not assignable to parameter of type 'RxCollectionCreator'.
Types of property 'schema' are incompatible.
Type '{ title: string; description: string; version: number; type: string; properties: { name: { type: ...' is not assignable to type 'RxJsonSchema | RxSchema<any>'.
Type '{ title: string; description: string; version: number; type: string; properties: { name: { type: ...' is not assignable to type 'RxSchema<any>'.
Property 'jsonID' is missing in type '{ title: string; description: string; version: number; type: string; properties: { name: { type: ...'
Если я добавлю jsonID
к своей схеме, он просто будет жаловаться на другое отсутствующее свойство, и прочее, и прочее.Очевидно, я сделал что-то не так.Любая мудрость в этом вопросе будет принята с благодарностью.