diff --git a/src/ParseQuery.ts b/src/ParseQuery.ts index c38b19121..b05b29d38 100644 --- a/src/ParseQuery.ts +++ b/src/ParseQuery.ts @@ -1560,12 +1560,13 @@ class ParseQuery { /** * Method to sort the full text search by text score + * `$score` is a special key used only for full text search ranking. * * @returns {Parse.Query} Returns the query, so you can chain this call. */ sortByTextScore() { this.ascending('$score'); - this.select(['$score'] as any); + this.select('$score'); return this; } @@ -1762,12 +1763,12 @@ class ParseQuery { /** * Sorts the results in ascending order by the given key. - * + * `$score` is a special key used only for full text search ranking. * @param {(string|string[])} keys The key to order by, which is a * string of comma separated values, or an Array of keys, or multiple keys. * @returns {Parse.Query} Returns the query, so you can chain this call. */ - ascending(...keys: string[]): this { + ascending(...keys: (K | K[])[]): this { this._order = []; return this.addAscending.apply(this, keys); } @@ -1780,7 +1781,7 @@ class ParseQuery { * string of comma separated values, or an Array of keys, or multiple keys. * @returns {Parse.Query} Returns the query, so you can chain this call. */ - addAscending(...keys: string[]): this { + addAscending(...keys: (K | K[])[]): this { if (!this._order) { this._order = []; } @@ -1801,7 +1802,7 @@ class ParseQuery { * string of comma separated values, or an Array of keys, or multiple keys. * @returns {Parse.Query} Returns the query, so you can chain this call. */ - descending(...keys: string[]): this { + descending(...keys: (K|K[])[]): this { this._order = []; return this.addDescending.apply(this, keys); } @@ -1814,7 +1815,7 @@ class ParseQuery { * string of comma separated values, or an Array of keys, or multiple keys. * @returns {Parse.Query} Returns the query, so you can chain this call. */ - addDescending(...keys: string[]): this { + addDescending(...keys: (K | K[])[]): this { if (!this._order) { this._order = []; } @@ -1926,10 +1927,12 @@ class ParseQuery { * longer configured is not included. To return all auth data regardless of * the provider configuration, do not select `authData`. * + * `$score` is a special key used only for full text search ranking. + * * @param {...string|Array} keys The name(s) of the key(s) to include. * @returns {Parse.Query} Returns the query, so you can chain this call. */ - select(...keys: (K | K[])[]): this { + select(...keys: (K | K[])[]): this { if (!this._select) { this._select = []; } diff --git a/types/ParseQuery.d.ts b/types/ParseQuery.d.ts index fbb92f65d..63420cc0c 100644 --- a/types/ParseQuery.d.ts +++ b/types/ParseQuery.d.ts @@ -618,6 +618,7 @@ declare class ParseQuery { fullText(key: K, value: string, options?: FullTextOptions): this; /** * Method to sort the full text search by text score + * `$score` is a special key used only for full text search ranking. * * @returns {Parse.Query} Returns the query, so you can chain this call. */ @@ -729,12 +730,12 @@ declare class ParseQuery { polygonContains(key: K, point: ParseGeoPoint): this; /** * Sorts the results in ascending order by the given key. - * + * `$score` is a special key used only for full text search ranking. * @param {(string|string[])} keys The key to order by, which is a * string of comma separated values, or an Array of keys, or multiple keys. * @returns {Parse.Query} Returns the query, so you can chain this call. */ - ascending(...keys: string[]): this; + ascending(...keys: (K | K[])[]): this; /** * Sorts the results in ascending order by the given key, * but can also add secondary sort descriptors without overwriting _order. @@ -743,7 +744,7 @@ declare class ParseQuery { * string of comma separated values, or an Array of keys, or multiple keys. * @returns {Parse.Query} Returns the query, so you can chain this call. */ - addAscending(...keys: string[]): this; + addAscending(...keys: (K | K[])[]): this; /** * Sorts the results in descending order by the given key. * @@ -751,7 +752,7 @@ declare class ParseQuery { * string of comma separated values, or an Array of keys, or multiple keys. * @returns {Parse.Query} Returns the query, so you can chain this call. */ - descending(...keys: string[]): this; + descending(...keys: (K | K[])[]): this; /** * Sorts the results in descending order by the given key, * but can also add secondary sort descriptors without overwriting _order. @@ -760,7 +761,7 @@ declare class ParseQuery { * string of comma separated values, or an Array of keys, or multiple keys. * @returns {Parse.Query} Returns the query, so you can chain this call. */ - addDescending(...keys: string[]): this; + addDescending(...keys: (K | K[])[]): this; /** * Sets the number of results to skip before returning any results. * This is useful for pagination. @@ -817,10 +818,12 @@ declare class ParseQuery { * longer configured is not included. To return all auth data regardless of * the provider configuration, do not select `authData`. * + * `$score` is a special key used only for full text search ranking. + * * @param {...string|Array} keys The name(s) of the key(s) to include. * @returns {Parse.Query} Returns the query, so you can chain this call. */ - select(...keys: (K | K[])[]): this; + select(...keys: (K | K[])[]): this; /** * Restricts the fields of the returned Parse.Objects to all keys except the * provided keys. Exclude takes precedence over select and include. diff --git a/types/tests.ts b/types/tests.ts index cd01952a2..c1a8e3eab 100644 --- a/types/tests.ts +++ b/types/tests.ts @@ -1895,22 +1895,40 @@ function testQuery() { // $ExpectType ParseQuery query.addAscending(['attribute1', 'attribute2', 'updatedAt']); - // $ExpectType ParseQuery query.addAscending('attribute1', 'attribute2', 'updatedAt'); - // $ExpectError query.addAscending(['attribute1', 'unexistenProp']); + // $ExpectType ParseQuery + query.addAscending('createdAt'); + // $ExpectType ParseQuery + query.addAscending('updatedAt'); + // $ExpectType ParseQuery + query.addAscending('objectId'); // $ExpectType ParseQuery query.addDescending(['attribute1', 'attribute2', 'createdAt']); // $ExpectError query.addDescending(['attribute1', 'unexistenProp']); + // $ExpectType ParseQuery + query.addDescending('createdAt'); + // $ExpectType ParseQuery + query.addDescending('updatedAt'); + // $ExpectType ParseQuery + query.addDescending('objectId'); // $ExpectType ParseQuery query.ascending(['attribute1', 'attribute2', 'objectId']); // $ExpectError query.ascending(['attribute1', 'nonexistentProp']); + // $ExpectType ParseQuery + query.ascending('createdAt'); + // $ExpectType ParseQuery + query.ascending('updatedAt'); + // $ExpectType ParseQuery + query.ascending('objectId'); + // $ExpectType ParseQuery ($score only used for full text queries) + query.ascending('$score'); // $ExpectType ParseQuery query.containedBy('attribute1', ['a', 'b', 'c']); @@ -1953,6 +1971,12 @@ function testQuery() { query.descending(['attribute1', 'attribute2', 'objectId']); // $ExpectError query.descending(['attribute1', 'nonexistentProp']); + // $ExpectType ParseQuery + query.descending('createdAt'); + // $ExpectType ParseQuery + query.descending('updatedAt'); + // $ExpectType ParseQuery + query.descending('objectId'); // $ExpectType ParseQuery query.doesNotExist('attribute1'); @@ -2134,6 +2158,8 @@ function testQuery() { query.select('attribute1', 'attribute2'); // $ExpectType ParseQuery query.select(['attribute1', 'attribute2']); + // $ExpectType ParseQuery ($score; only used for full text search ranking) + query.select('$score'); // $ExpectError query.select('attribute1', 'nonexistentProp');