Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -1148,9 +1148,9 @@ class ParseQuery<T extends ParseObject = ParseObject> {
key: K,
value:
| T['attributes'][K]
| (T['attributes'][K] extends ParseObject
| (NonNullable<T['attributes'][K]> extends ParseObject
? Pointer
: T['attributes'][K] extends (infer E)[]
: NonNullable<T['attributes'][K]> extends (infer E)[]
? E
: never)
): this {
Expand All @@ -1177,9 +1177,9 @@ class ParseQuery<T extends ParseObject = ParseObject> {
key: K,
value:
| T['attributes'][K]
| (T['attributes'][K] extends ParseObject
| (NonNullable<T['attributes'][K]> extends ParseObject
? Pointer
: T['attributes'][K] extends (infer E)[]
: NonNullable<T['attributes'][K]> extends (infer E)[]
? E
: never)
): this {
Expand Down
4 changes: 2 additions & 2 deletions types/ParseQuery.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ declare class ParseQuery<T extends ParseObject = ParseObject> {
* @param value The value that the Parse.Object must contain.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
equalTo<K extends keyof T['attributes'] | keyof BaseAttributes>(key: K, value: T['attributes'][K] | (T['attributes'][K] extends ParseObject ? Pointer : T['attributes'][K] extends (infer E)[] ? E : never)): this;
equalTo<K extends keyof T['attributes'] | keyof BaseAttributes>(key: K, value: T['attributes'][K] | (NonNullable<T['attributes'][K]> extends ParseObject ? Pointer : NonNullable<T['attributes'][K]> extends (infer E)[] ? E : never)): this;
/**
* Adds a constraint to the query that requires a particular key's value to
* be not equal to the provided value.
Expand All @@ -426,7 +426,7 @@ declare class ParseQuery<T extends ParseObject = ParseObject> {
* @param value The value that must not be equalled.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
notEqualTo<K extends keyof T['attributes'] | keyof BaseAttributes>(key: K, value: T['attributes'][K] | (T['attributes'][K] extends ParseObject ? Pointer : T['attributes'][K] extends (infer E)[] ? E : never)): this;
notEqualTo<K extends keyof T['attributes'] | keyof BaseAttributes>(key: K, value: T['attributes'][K] | (NonNullable<T['attributes'][K]> extends ParseObject ? Pointer : NonNullable<T['attributes'][K]> extends (infer E)[] ? E : never)): this;
/**
* Adds a constraint to the query that requires a particular key's value to
* be less than the provided value.
Expand Down
24 changes: 24 additions & 0 deletions types/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1888,6 +1888,8 @@ function testQuery() {
attribute2: number;
attribute3: AnotherSubClass;
attribute4: string[];
attribute5?: AnotherSubClass[];
attribute6?: string[];
}> {}
const query = new Parse.Query(MySubClass);

Expand Down Expand Up @@ -1997,6 +1999,22 @@ function testQuery() {
// $ExpectType ParseQuery<MySubClass>
query.equalTo('attribute4', ['a_string_value']);


// Optional object[] (e.g. prop?: ClassName[] ): allow matching a single element (array contains object), and allow matching the full array
// $ExpectType ParseQuery<MySubClass>
query.equalTo('attribute5', new AnotherSubClass());
// $ExpectType ParseQuery<MySubClass>
query.equalTo('attribute5', [new AnotherSubClass()]);
// Since there is no `$ExpectNotError` thing, this line is instead used to at least prove that there is no regression for type safety for `Array of object` fields
// $ExpectError
query.equalTo('attribute5', new MySubClass());

// Optional string[] (e.g. prop?: string[] ): allow matching a single element (array contains string), and allow matching the full array
// $ExpectType ParseQuery<MySubClass>
query.equalTo('attribute6', 'a_string_value');
// $ExpectType ParseQuery<MySubClass>
query.equalTo('attribute6', ['a_string_value']);

// $ExpectType ParseQuery<MySubClass>
query.notEqualTo('attribute4', 'a_string_value');
// $ExpectType ParseQuery<MySubClass>
Expand All @@ -2011,6 +2029,12 @@ function testQuery() {
// $ExpectError
query.notEqualTo('attribute4', [5]);

// Optional string[]: reject invalid element types
// $ExpectError
query.equalTo('attribute6', 5);
// $ExpectError
query.notEqualTo('attribute6', 5);

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