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/04/23 14:06:29 UTC

[GitHub] [couchdb-nano] BigsonLvrocha opened a new issue #219: [Types]: Add string as input type for View.map property

BigsonLvrocha opened a new issue #219:
URL: https://github.com/apache/couchdb-nano/issues/219


   
   ## 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 -->
   I should be able to define functions passing a string to views field
   ```typescript
   await handle.insert({
         _id: '_design/des',
         view: {
           view1: `
             function (doc) {
               if (doc.ClassName === 'viewClass') {
                 emit([doc.key1, doc.key2])
               }
             }
           `
         }
       })
   ```
   ## 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 -->
   
   It throws the error
   
   ```
   Argument of type '{ _id: string; view: { view1: string; }; }' is not assignable to parameter of type 'ViewDocument<ActionCouchDoc> | (ActionCouchDoc & MaybeDocument)'.
     Object literal may only specify known properties, and 'view' does not exist in type 'ViewDocument<ActionCouchDoc> | (ActionCouchDoc & MaybeDocument)
   ```
   
   ## Possible Solution
   <!--- Not obligatory, but suggest a fix/reason for the bug, -->
   <!--- or ideas how to implement the addition or change -->
   change
   ```typescript
   type DocumentInfer<D> = (doc: D & Document) => void
     interface View<D> {
       map?:DocumentInfer<D>;
       reduce?: string | DocumentInfer<D>
       
     }
   
     interface ViewDocument<D> extends IdentifiedDocument {
       views: {
         [name: string]: View<D>
       };
     }
   ```
   to
   ```typescript
   type DocumentInfer<D> = (doc: D & Document) => void
     interface View<D> {
       map?:string |DocumentInfer<D>;
       reduce?: string | DocumentInfer<D>
       
     }
   
     interface ViewDocument<D> extends IdentifiedDocument {
       views: {
         [name: string]: View<D>
       };
     }
   ```
   
   ## 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 -->
   I've been having to cast the string to any for it to stop complaining and it still woks
   
   ```typescript
   await handle.insert({
         _id: '_design/des',
         view: {
           view1: `
             function (doc) {
               if (doc.ClassName === 'viewClass') {
                 emit([doc.key1, doc.key2])
               }
             }
           `
         }
       })
   ```
   ## Your Environment
   <!--- Include as many relevant details about the environment you experienced the bug in -->
   * Version used: ^8.2.2
   * Browser Name and version: Node 10.16 typescript 3.8.3
   * Operating System and version (desktop or mobile): Ubuntu
   * Link to your project: private
   


----------------------------------------------------------------
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