It seem I cant find solution on this. using upsert on pouchdb I am getting TS2345
and or TS2339
.
I tried using it like htis.
db.upsert('id', doc => {
doc.p = 'sample';
return doc;
});
but on the doc.p
I am getting TS2339
Property 'p' does not exist on type '{} | IdMeta'
and base on pouchdb-upsert/index.d.ts it has this definition
upsert<Model>(docId: Core.DocumentId, diffFun: UpsertDiffCallback<Content & Model>): Promise<UpsertResponse>;
So I tried this
db.upsert<{ p: string }>('id', doc => {
doc.p = 'sample';
return doc;
});
but now I am getting TS2345
and TS2339
. here is the error
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)
Anyone? please, thanks.
Update
When I test it like this:
public test() {
new PouchDB('test').upsert<{ p: string }>('id', doc => {
doc.p = 'test string';
return doc;
})
}
I am getting this:
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)
While if I do it like this:
public test2() {
new PouchDB<{ p: string }>('test').upsert('id', doc => {
doc.p = 'test string';
return doc;
})
}
I am getting this:
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)