【发布时间】:2019-04-15 23:34:59
【问题描述】:
我似乎无法找到解决方案。使用upsert on pouchdb 我得到TS2345 和或TS2339。
我尝试像 htis 一样使用它。
db.upsert('id', doc => {
doc.p = 'sample';
return doc;
});
但是在doc.p 上,我收到了TS2339 Property 'p' does not exist on type '{} | IdMeta'
并且基于 pouchdb-upsert/index.d.ts 它有这个定义
upsert<Model>(docId: Core.DocumentId, diffFun: UpsertDiffCallback<Content & Model>): Promise<UpsertResponse>;
所以我尝试了这个
db.upsert<{ p: string }>('id', doc => {
doc.p = 'sample';
return doc;
});
但现在我收到了TS2345 和TS2339。这是错误
Argument of type '(doc: {} | Document<{ p: string; }>) => {} | Document<{ p: string; }>' is not assignable to parameter of type 'UpsertDiffCallback<{ p: string; }>'.
Type '{} | Document<{ p: string; }>' is not assignable to type 'false | "" | 0 | ({ p: string; } & Partial<IdMeta>) | null | undefined'.
Type '{}' is not assignable to type 'false | "" | 0 | ({ p: string; } & Partial<IdMeta>) | null | undefined'.
Type '{}' is not assignable to type '{ p: string; } & Partial<IdMeta>'.
Type '{}' is not assignable to type '{ p: string; }'.
Property 'p' is missing in type '{}'. (typescript-tide)
有人吗?请,谢谢。
更新
当我这样测试时:
public test() {
new PouchDB('test').upsert<{ p: string }>('id', doc => {
doc.p = 'test string';
return doc;
})
}
我得到了这个:
Argument of type '(doc: Partial<Document<{ p: string; }>>) => Partial<Document<{ p: string; }>>' is not assignable to parameter of type 'UpsertDiffCallback<{ p: string; }>'.
Type 'Partial<Document<{ p: string;; }>>' is not assignable to type 'false | "" | 0 | ({ p: string; } & Partial<IdMeta>) | null | undefined'.
Type 'Partial<Document<{ p: string; }>>' is not assignable to type '{ p: string; } & Partial<IdMeta>'.
Type 'Partial<Document<{ p: string; }>>' is not assignable to type '{ p: string; }'.
Types of property 'p' are incompatible.
Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'. (typescript-tide)
如果我这样做:
public test2() {
new PouchDB<{ p: string }>('test').upsert('id', doc => {
doc.p = 'test string';
return doc;
})
}
我得到了这个:
Argument of type '(doc: Partial<Document<{ p: string; }>>) => Partial<Document<{ p: string; }>>' is not assignable to parameter of type 'UpsertDiffCallback<{ p: string; } & Partial<Document<{ p: string; }>>>'.
Type 'Partial<Document<{ p: string; }>>' is not assignable to type 'false | "" | 0 | ({ p: string; } & Partial<Document<{ p: string; }>> & Partial<IdMeta>) | null | ...'.
Type 'Partial<Document<{ p: string; }>>' is not assignable to type '{ p: string; } & Partial<Document<{ p: string; }>> & Partial<IdMeta>'.
Type 'Partial<Document<{ p: string; }>>' is not assignable to type '{ p: string; }'.
Types of property 'p' are incompatible.
Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'. (typescript-tide)
【问题讨论】:
标签: typescript pouchdb upsert