You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2020/02/12 16:48:47 UTC

[GitHub] [couchdb-nano] Agnaro opened a new issue #198: Incomplete return type definition for bulk()

Agnaro opened a new issue #198: Incomplete return type definition for bulk()
URL: https://github.com/apache/couchdb-nano/issues/198
 
 
   <!--- Provide a general summary of the issue in the Title above -->
   The type definition for the `bulk()` function lists a return type (in both callback and promise) of `DocumentInsertResponse[]`.
   
   `DocumentInsertResponse` only covers case where the operation is successful (id+ok+rev), but does not cover the error case e.g.
   ```javascript
   [
     { id: '1', error: 'conflict', reason: 'Document update conflict.' },
     { ok: true, id: '2', rev: '1-e930be0936bead4354f6a20203e9a9dc' }
   ]
   ```
   
   ## Expected Behavior
   <!--- If you're describing a bug, tell us what should happen -->
   <!--- If you're suggesting a change/improvement, tell us how it should work -->
   The type definition for the `bulk()` function should specify a return type that matches the [CouchDB API](http://docs.couchdb.org/en/latest/api/database/bulk-api.html#post--db-_bulk_docs):
   
   >- **id** _(string)_ - Document ID
   >- **rev** _(string)_ - New document revision token. Available if document has saved without errors. _Optional_
   >- **error** _(string)_ - Error type. _Optional_
   >- **reason** _(string)_ - Error reason. _Optional_
   
   ## Current Behavior
   <!--- If describing a bug, tell us what happens instead of the expected behavior -->
   <!--- If suggesting a change/improvement, explain the difference from current behavior -->
   Currently, in the array of objects returned from a `bulk()` operation, TypeScript will not allow access to the `error` or `reason` properties on those objects even though they may exist because the type definition says they will not exist.
   
   ## Possible Solution
   <!--- Not obligatory, but suggest a fix/reason for the bug, -->
   <!--- or ideas how to implement the addition or change -->
   In the `nano.d.ts` file, add a `DocumentBulkResponse` type and change the bulk() function to return this type:
   
   ```typescript
   interface DocumentBulkResponse {
     id: string;
     rev?: string;
     error?: string;
     reason?: string
   }
   ```
   This implementation mirrors the `DatabaseCreateResponse` type.  It could also be implemented using a type that is a union of success and error types.
   
   ## Steps to Reproduce (for bugs)
   <!--- Provide a link to a live example, or an unambiguous set of steps to -->
   <!--- reproduce this bug. Include code to reproduce, if relevant -->
   N/A
   
   ## Context
   <!--- How has this issue affected you? What are you trying to accomplish? -->
   <!--- Providing context helps us come up with a solution that is most useful in the real world -->
   Incomplete type definition can make TypeScript developers think that a return value will be in a certain structure when the runtime data structure is actually different, leading to bugs.
   
   ## Your Environment
   <!--- Include as many relevant details about the environment you experienced the bug in -->
   * Version used: 8.1.0
   * Browser Name and version: NodeJS v12.15.0
   * TypeScript version: 3.5.3
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [couchdb-nano] glynnbird closed issue #198: Incomplete return type definition for bulk()

Posted by GitBox <gi...@apache.org>.
glynnbird closed issue #198: Incomplete return type definition for bulk()
URL: https://github.com/apache/couchdb-nano/issues/198
 
 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services