Dig*_*dra 3 realm typescript react-native
我正在使用 Realm 进行本机反应。他们说如果你想在对象上使用模式,你会做这样的事情:
class Person {
[...]
}
Person.schema = PersonSchema;
// Note here we are passing in the `Person` constructor
let realm = new Realm({schema: [CarSchema, Person]});
Run Code Online (Sandbox Code Playgroud)
我想在我的项目中使用 Typescript。的类型定义schema是ObjectClass[]whereObjectClass定义为:
interface ObjectClass {
schema: ObjectSchema;
}
interface ObjectSchema {
name: string;
primaryKey?: string;
properties: PropertiesTypes;
}
[ omitted the rest b/c that's not where the type fails ]
Run Code Online (Sandbox Code Playgroud)
所以,我定义了我的班级:
class MyApp implements ObjectClass{
schema: { name: 'int', properties: { version: 'int' } }
}
Run Code Online (Sandbox Code Playgroud)
但是,以下失败:
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'.
在schema财产上MyApp应该是静态的(你将不能够实现的接口此方法ObjectClass):
class MyApp {
static schema = { name: 'int', properties: { version: 'int' } };
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3592 次 |
| 最近记录: |