mkeology opened a new issue #147: typescript: compilation error : Types of property 'sort' are incompatible. URL: https://github.com/apache/couchdb-nano/issues/147 <!--- Provide a general summary of the issue in the Title above --> When I add to a find query, a SORT instruction which is of an ordering type { [key: string]: 'asc' | 'desc' };, I encounter a typescript error : error TS2345: Argument of type '{ selector: { myAttribut: { "$eq": string; }; }; use_index: string; sort: { "attr_set_in_index": string; }; limit: number; update: boolean; execution_stats: boolean; }' is not assignable to parameter of type 'MangoQuery'. Types of property 'sort' are incompatible. Type '{ "attr_set_in_index": string; }' is missing the following properties from type 'SortOrder[]': length, pop, push, concat, and 26 more. Example Type script myMethod(){ const q = { selector: { myAttribut: { "$eq": 'mydataValue' }, }, use_index: 'myIndex', sort: {"attr_set_in_index": "desc"}, limit: 10, update: true, execution_stats: true }; } I have tried the following syntax styles to no prevail := sort: { attr_set_in_index : 'desc'}, sort: [{"attr_set_in_index": 'desc'}], sort: [{attr_set_in_index: "desc"}], sort: {attr_set_in_index: 'desc'}, Any help would be more than welcome....thanks. ## 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 --> To compile with the following line : sort: {"attr_set_in_index": "desc"}, and execute the resulting Mongoose query 👍 Mango Query { "selector": { "myAttribut": { "$eq": "mydataValue" } }, "sort": [ { "attr_set_in_index": "desc" } ], "use_index": "myIndex", "execution_stats": true } Which works in my couchDB GUI ;-) ## 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 --> error TS2345: Argument of type '{ selector: { myAttribut: { "$eq": string; }; }; use_index: string; sort: { "attr_set_in_index": string; }; limit: number; update: boolean; execution_stats: boolean; }' is not assignable to parameter of type 'MangoQuery'. Types of property 'sort' are incompatible. Type '{ "attr_set_in_index": string; }' is missing the following properties from type 'SortOrder[]': length, pop, push, concat, and 26 more. ## Possible Solution <!--- Not obligatory, but suggest a fix/reason for the bug, --> <!--- or ideas how to implement the addition or change --> I don't have any... Even though the following syntax works it is not sufficient (as it's using the default order :asc) : sort: ["x_timestamp", "type"], ## 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. Create a typescript nodejs project 2. create a find query 3. change to sort attribute to a { [key: string]: 'asc' | 'desc' } type 4. create the typescript query and compile ## 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 --> Attach a sort descriptor to a doc attribut with a certain order direction according to the docs : Reference Typescript : https://github.com/apache/couchdb-nano/blob/master/lib/nano.d.ts // http://docs.couchdb.org/en/latest/api/database/find.html#sort-syntax type SortOrder = string | string[] | { [key: string]: 'asc' | 'desc' }; interface MangoQuery { .... // JSON array following sort syntax. sort?: SortOrder[]; ....} ## Your Environment <!--- Include as many relevant details about the environment you experienced the bug in --> * Version used: * Browser Name and version: * Operating System and version (desktop or mobile): * Link to your project: nodejs: v8.15.0 npm:6.4.1 OS: linux, Mac package.json "dependencies": { "nano": "^8.0.0", "typescript": "^3.0.1", }, "devDependencies": { "@types/node": "^10.7.1", "nodemon": "^1.18.3", "ts-node": "^7.0.1", "tsconfig-paths": "^3.5.0", }, ts-config.json { "compileOnSave": true, "compilerOptions": { "moduleResolution": "node", "declaration": false, "experimentalDecorators": true, "emitDecoratorMetadata": true, "module": "commonjs", "newLine": "LF", "noFallthroughCasesInSwitch": true, "noImplicitAny": false, "noImplicitReturns": true, "noImplicitThis": false, "noUnusedParameters": false, "noUnusedLocals": true, "outDir": "./dist", "skipLibCheck": true, "sourceMap": false, "strictNullChecks": false, "target": "es6" }, "include": [ "./src/**/*.ts" ] }
---------------------------------------------------------------- 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
