Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/ParseQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1767,7 +1767,7 @@ class ParseQuery<T extends ParseObject = ParseObject> {
* 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<K extends keyof T['attributes'] | keyof BaseAttributes>(...keys: (K | K[])[]): this {
this._order = [];
return this.addAscending.apply(this, keys);
}
Expand All @@ -1780,7 +1780,7 @@ class ParseQuery<T extends ParseObject = ParseObject> {
* 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<K extends keyof T['attributes'] | keyof BaseAttributes>(...keys: (K | K[])[]): this {
if (!this._order) {
this._order = [];
}
Expand All @@ -1801,7 +1801,7 @@ class ParseQuery<T extends ParseObject = ParseObject> {
* 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<K extends keyof T['attributes'] | keyof BaseAttributes>(...keys: (K|K[])[]): this {
this._order = [];
return this.addDescending.apply(this, keys);
}
Expand All @@ -1814,7 +1814,7 @@ class ParseQuery<T extends ParseObject = ParseObject> {
* 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<K extends keyof T['attributes'] | keyof BaseAttributes>(...keys: (K | K[])[]): this {
if (!this._order) {
this._order = [];
}
Expand Down
8 changes: 4 additions & 4 deletions types/ParseQuery.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ declare class ParseQuery<T extends ParseObject = ParseObject> {
* 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<K extends keyof T['attributes'] | keyof BaseAttributes>(...keys: (K | K[])[]): this;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
/**
* Sorts the results in ascending order by the given key,
* but can also add secondary sort descriptors without overwriting _order.
Expand All @@ -743,15 +743,15 @@ declare class ParseQuery<T extends ParseObject = ParseObject> {
* 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<K extends keyof T['attributes'] | keyof BaseAttributes>(...keys: (K | K[])[]): this;
/**
* Sorts the results in descending order by the given key.
*
* @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.
*/
descending(...keys: string[]): this;
descending<K extends keyof T['attributes'] | keyof BaseAttributes>(...keys: (K | K[])[]): this;
/**
* Sorts the results in descending order by the given key,
* but can also add secondary sort descriptors without overwriting _order.
Expand All @@ -760,7 +760,7 @@ declare class ParseQuery<T extends ParseObject = ParseObject> {
* 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<K extends keyof T['attributes'] | keyof BaseAttributes>(...keys: (K | K[])[]): this;
/**
* Sets the number of results to skip before returning any results.
* This is useful for pagination.
Expand Down
26 changes: 24 additions & 2 deletions types/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1895,22 +1895,38 @@ function testQuery() {

// $ExpectType ParseQuery<MySubClass>
query.addAscending(['attribute1', 'attribute2', 'updatedAt']);

// $ExpectType ParseQuery<MySubClass>
query.addAscending('attribute1', 'attribute2', 'updatedAt');

// $ExpectError
query.addAscending(['attribute1', 'unexistenProp']);
// $ExpectType ParseQuery<MySubClass>
query.addAscending('createdAt');
// $ExpectType ParseQuery<MySubClass>
query.addAscending('updatedAt');
// $ExpectType ParseQuery<MySubClass>
query.addAscending('objectId');

// $ExpectType ParseQuery<MySubClass>
query.addDescending(['attribute1', 'attribute2', 'createdAt']);
// $ExpectError
query.addDescending(['attribute1', 'unexistenProp']);
// $ExpectType ParseQuery<MySubClass>
query.addDescending('createdAt');
// $ExpectType ParseQuery<MySubClass>
query.addDescending('updatedAt');
// $ExpectType ParseQuery<MySubClass>
query.addDescending('objectId');

// $ExpectType ParseQuery<MySubClass>
query.ascending(['attribute1', 'attribute2', 'objectId']);
// $ExpectError
query.ascending(['attribute1', 'nonexistentProp']);
// $ExpectType ParseQuery<MySubClass>
query.ascending('createdAt');
// $ExpectType ParseQuery<MySubClass>
query.ascending('updatedAt');
// $ExpectType ParseQuery<MySubClass>
query.ascending('objectId');

// $ExpectType ParseQuery<MySubClass>
query.containedBy('attribute1', ['a', 'b', 'c']);
Expand Down Expand Up @@ -1953,6 +1969,12 @@ function testQuery() {
query.descending(['attribute1', 'attribute2', 'objectId']);
// $ExpectError
query.descending(['attribute1', 'nonexistentProp']);
// $ExpectType ParseQuery<MySubClass>
query.descending('createdAt');
// $ExpectType ParseQuery<MySubClass>
query.descending('updatedAt');
// $ExpectType ParseQuery<MySubClass>
query.descending('objectId');

// $ExpectType ParseQuery<MySubClass>
query.doesNotExist('attribute1');
Expand Down