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:
[email protected]


With regards,
Apache Git Services

Reply via email to