apache / couchdb-nano

Nano: The official Apache CouchDB library for Node.js
https://www.npmjs.com/package/nano
Apache License 2.0
651 stars 165 forks source link

Cannot acces the document content using typescript #308

Closed Kaspanoombro closed 1 year ago

Kaspanoombro commented 1 year ago

Expected Behavior

TS keeps giving error, although it works.

Steps to Reproduce

  1. nano.db .use('mydatabase') .get("docidxxxxx") //return a type DocumentGetResponse .then(result=>{ console.log(result); //correctly prints the document (not a DocumentGetResponse) const prop1=result.prop1; //Ts gives the error Property 'prop1' does not exist on type 'DocumentGetResponse'.ts(2339) const { prop1, _id } = result; //gives the same error }

this .get() does not have .pipe() which i could use to deconstruct the object with the map. How can i access correctly to the document properties using TS? Thank you.

Kaspanoombro commented 1 year ago

The solution was

.then(result=>{ const converted = results as mydocModel; const prop1=converted.prop1; //now works }