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/03/03 08:36:25 UTC

[GitHub] [couchdb-nano] alkihis opened a new issue #211: Incorrect type definition for MangoSelector in nano 8.2.1

alkihis opened a new issue #211: Incorrect type definition for MangoSelector in nano 8.2.1
URL: https://github.com/apache/couchdb-nano/issues/211
 
 
   <!--- Provide a general summary of the issue in the Title above -->
   After upgrading to nano 8.2.1, all my queries using a MangoSelector (typically, db.find()) fail type checking.
   
   ## 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 code actually works if we use @ts-ignore, it worked before as well.
   This should just not throw a type error.
   
   ## Possible Solution
   <!--- Not obligatory, but suggest a fix/reason for the bug, -->
   <!--- or ideas how to implement the addition or change -->
   The MangoSelector type in nano.d.ts is defined as:
   ```ts
   type MangoSelector = {
       [K in MangoOperator]: MangoSelector | MangoValue | MangoValue[];
   }
   ```
   with the type MangoOperator as `type MangoOperator = '$lt' | '$lte' | '$eq' | ...`.
   
   Problem here are only operators can be used as selector keys: we can't use "normal" keys for selecting a field in our document.
   
   ## 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 -->
   1. Instanciate nano
   2. Choose a database
   3. Use find() method
   
   ```ts
   const user_db = nano('url').use('user');
   user_db.find({ selector: { role: 'admin' } });
   //                                       ^^^^^^^^^^^^^^
   // TS-2332 Unable to assign type '{ role: string; }' to type 'MangoSelector'.
   ```
   
   ## Your Environment
   <!--- Include as many relevant details about the environment you experienced the bug in -->
   * Version used: 8.2.1
   * Browser Name and version: Node 13 with TypeScript 3.8
   
   ## Workaround
   
   Modifying type definition in node_modules works.
   I changed MangoSelector type to:
   ```
   interface MangoSelector {
       [key: string]: MangoSelector | MangoValue | MangoValue[];
   }
   ```

----------------------------------------------------------------
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 commented on issue #211: Incorrect type definition for MangoSelector

Posted by GitBox <gi...@apache.org>.
glynnbird commented on issue #211: Incorrect type definition for MangoSelector
URL: https://github.com/apache/couchdb-nano/issues/211#issuecomment-593835446
 
 
   Maybe this change models it better?
   
   ```ts
     type MangoSelector = {
       [K in MangoOperator | string]: MangoSelector | MangoValue | MangoValue[];
     }
   ```
   
   What do you think @alkihis?

----------------------------------------------------------------
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] alkihis commented on issue #211: Incorrect type definition for MangoSelector

Posted by GitBox <gi...@apache.org>.
alkihis commented on issue #211: Incorrect type definition for MangoSelector
URL: https://github.com/apache/couchdb-nano/issues/211#issuecomment-593841565
 
 
   Seems to be a working and nicer solution!

----------------------------------------------------------------
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 commented on issue #211: Incorrect type definition for MangoSelector

Posted by GitBox <gi...@apache.org>.
glynnbird commented on issue #211: Incorrect type definition for MangoSelector
URL: https://github.com/apache/couchdb-nano/issues/211#issuecomment-593833230
 
 
   Thanks for this. Of course a MangoSelector can either have a MangoOperator (e.g "$and") at the top level, or just a string ("role"). I'll make and adjustment to the template. 👍 

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