【发布时间】:2017-11-12 05:06:28
【问题描述】:
我将 Realm 用于 react-native。他们说如果你想在对象上使用模式,你会这样做:
class Person {
[...]
}
Person.schema = PersonSchema;
// Note here we are passing in the `Person` constructor
let realm = new Realm({schema: [CarSchema, Person]});
我想在我的项目中使用 Typescript。 schema 的类型定义为 ObjectClass[],其中 ObjectClass 定义为:
interface ObjectClass {
schema: ObjectSchema;
}
interface ObjectSchema {
name: string;
primaryKey?: string;
properties: PropertiesTypes;
}
[ omitted the rest b/c that's not where the type fails ]
所以,我定义了我的班级:
class MyApp implements ObjectClass{
schema: { name: 'int', properties: { version: 'int' } }
}
但是,以下失败:
let realm = new Realm({schema: [MyApp]})
Argument of type 'typeof MyApp' is not assignable to parameter of type 'ObjectClass'. Property 'schema' is missing in type 'typeof MyApp'.
【问题讨论】:
标签: typescript react-native realm