Skip to content

Commit 948eb14

Browse files
committed
fix todos
1 parent 5be5221 commit 948eb14

File tree

5 files changed

+61
-28
lines changed

5 files changed

+61
-28
lines changed

src/ParseObject.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class ParseObject<T extends Attributes = Attributes> {
154154
*/
155155
constructor(
156156
className?: string | { className: string; [attr: string]: any },
157-
attributes?: T | Attributes,
157+
attributes?: T,
158158
options?: SetOptions
159159
) {
160160
// Enable legacy initializers

src/ParseQuery.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,10 +1922,12 @@ class ParseQuery<T extends ParseObject = ParseObject> {
19221922
* @param {...string|Array<string>} keys The name(s) of the key(s) to include.
19231923
* @returns {Parse.Query} Returns the query, so you can chain this call.
19241924
*/
1925-
include(...keys: Array<string | Array<string>>): this {
1925+
include<K extends keyof T['attributes'] | keyof BaseAttributes>(
1926+
...keys: Array<K | Array<K>>
1927+
): this {
19261928
keys.forEach(key => {
19271929
if (Array.isArray(key)) {
1928-
this._include = this._include.concat(key);
1930+
this._include = this._include.concat(key as string[]);
19291931
} else {
19301932
this._include.push(key as string);
19311933
}
@@ -1952,13 +1954,15 @@ class ParseQuery<T extends ParseObject = ParseObject> {
19521954
* @param {...string|Array<string>} keys The name(s) of the key(s) to include.
19531955
* @returns {Parse.Query} Returns the query, so you can chain this call.
19541956
*/
1955-
select(...keys: Array<string | Array<string>>): this {
1957+
select<K extends keyof T['attributes'] | keyof BaseAttributes>(
1958+
...keys: Array<K | Array<K>>
1959+
): this {
19561960
if (!this._select) {
19571961
this._select = [];
19581962
}
19591963
keys.forEach(key => {
19601964
if (Array.isArray(key)) {
1961-
this._select = this._select.concat(key);
1965+
this._select = this._select.concat(key as string[]);
19621966
} else {
19631967
this._select.push(key as string);
19641968
}
@@ -1975,10 +1979,12 @@ class ParseQuery<T extends ParseObject = ParseObject> {
19751979
* @param {...string|Array<string>} keys The name(s) of the key(s) to exclude.
19761980
* @returns {Parse.Query} Returns the query, so you can chain this call.
19771981
*/
1978-
exclude(...keys: Array<string | Array<string>>): this {
1982+
exclude<K extends keyof T['attributes'] | keyof BaseAttributes>(
1983+
...keys: Array<K | Array<K>>
1984+
): this {
19791985
keys.forEach(key => {
19801986
if (Array.isArray(key)) {
1981-
this._exclude = this._exclude.concat(key);
1987+
this._exclude = this._exclude.concat(key as string[]);
19821988
} else {
19831989
this._exclude.push(key as string);
19841990
}
@@ -1994,10 +2000,12 @@ class ParseQuery<T extends ParseObject = ParseObject> {
19942000
* @param {...string|Array<string>} keys The name(s) of the key(s) to watch.
19952001
* @returns {Parse.Query} Returns the query, so you can chain this call.
19962002
*/
1997-
watch(...keys: Array<string | Array<string>>): this {
2003+
watch<K extends keyof T['attributes'] | keyof BaseAttributes>(
2004+
...keys: Array<K | Array<K>>
2005+
): this {
19982006
keys.forEach(key => {
19992007
if (Array.isArray(key)) {
2000-
this._watch = this._watch.concat(key);
2008+
this._watch = this._watch.concat(key as string[]);
20012009
} else {
20022010
this._watch.push(key as string);
20032011
}

types/ParseObject.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ declare class ParseObject<T extends Attributes = Attributes> {
100100
className: string;
101101
[attr: string]: any;
102102
},
103-
attributes?: T | Attributes,
103+
attributes?: T,
104104
options?: SetOptions
105105
);
106106
/**

types/ParseQuery.d.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,9 @@ declare class ParseQuery<T extends ParseObject = ParseObject> {
940940
* @param {...string|Array<string>} keys The name(s) of the key(s) to include.
941941
* @returns {Parse.Query} Returns the query, so you can chain this call.
942942
*/
943-
include(...keys: Array<string | Array<string>>): this;
943+
include<K extends keyof T['attributes'] | keyof BaseAttributes>(
944+
...keys: Array<K | Array<K>>
945+
): this;
944946
/**
945947
* Includes all nested Parse.Objects one level deep.
946948
*
@@ -957,7 +959,9 @@ declare class ParseQuery<T extends ParseObject = ParseObject> {
957959
* @param {...string|Array<string>} keys The name(s) of the key(s) to include.
958960
* @returns {Parse.Query} Returns the query, so you can chain this call.
959961
*/
960-
select(...keys: Array<string | Array<string>>): this;
962+
select<K extends keyof T['attributes'] | keyof BaseAttributes>(
963+
...keys: Array<K | Array<K>>
964+
): this;
961965
/**
962966
* Restricts the fields of the returned Parse.Objects to all keys except the
963967
* provided keys. Exclude takes precedence over select and include.
@@ -967,7 +971,9 @@ declare class ParseQuery<T extends ParseObject = ParseObject> {
967971
* @param {...string|Array<string>} keys The name(s) of the key(s) to exclude.
968972
* @returns {Parse.Query} Returns the query, so you can chain this call.
969973
*/
970-
exclude(...keys: Array<string | Array<string>>): this;
974+
exclude<K extends keyof T['attributes'] | keyof BaseAttributes>(
975+
...keys: Array<K | Array<K>>
976+
): this;
971977
/**
972978
* Restricts live query to trigger only for watched fields.
973979
*
@@ -976,7 +982,7 @@ declare class ParseQuery<T extends ParseObject = ParseObject> {
976982
* @param {...string|Array<string>} keys The name(s) of the key(s) to watch.
977983
* @returns {Parse.Query} Returns the query, so you can chain this call.
978984
*/
979-
watch(...keys: Array<string | Array<string>>): this;
985+
watch<K extends keyof T['attributes'] | keyof BaseAttributes>(...keys: Array<K | Array<K>>): this;
980986
/**
981987
* Changes the read preference that the backend will use when performing the query to the database.
982988
*

types/tests.ts

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ async function test_query() {
144144
query.include('score');
145145
query.include('score', 'team');
146146
query.include(['score.team']);
147+
query.include('*');
147148
query.includeAll();
148149
query.sortByTextScore();
149150
// Find objects that match the aggregation pipeline
@@ -1094,14 +1095,14 @@ function testObject() {
10941095
// $ExpectType ParseObject<{ example: string; }>
10951096
new Parse.Object('TestObject', { example: 'hello' }, { ignoreValidation: true });
10961097

1097-
// // $ExpectError todo
1098-
// new Parse.Object<{ example: string }>('TestObject');
1098+
// $ExpectType ParseObject<{ example: string; }>
1099+
new Parse.Object<{ example: string }>('TestObject');
10991100

11001101
// $ExpectType ParseObject<{ example: number; }>
11011102
new Parse.Object<{ example: number }>('TestObject', { example: 100 });
11021103

1103-
// // $ExpectError todo
1104-
// new Parse.Object<{ example: boolean }>('TestObject', { example: 'hello' });
1104+
// $ExpectError
1105+
new Parse.Object<{ example: boolean }>('TestObject', { example: 'hello' });
11051106
}
11061107

11071108
function testStaticMethods() {
@@ -1721,8 +1722,8 @@ function testInstallation() {
17211722
// $ExpectType ParseInstallation<{ example: number; }>
17221723
new Parse.Installation({ example: 100 });
17231724

1724-
// // $ExpectError todo
1725-
// new Parse.Installation<{ example: number }>();
1725+
// $ExpectType ParseInstallation<{ example: number; }>
1726+
new Parse.Installation<{ example: number }>();
17261727

17271728
// $ExpectType ParseInstallation<{ example: number; }>
17281729
new Parse.Installation<{ example: number }>({ example: 100 });
@@ -1914,9 +1915,18 @@ function testQuery() {
19141915
// $ExpectType ParseQuery<MySubClass>
19151916
query.include(['attribute1', 'attribute2']);
19161917
// $ExpectType ParseQuery<MySubClass>
1918+
query.include('attribute1', 'attribute2');
1919+
// $ExpectType ParseQuery<MySubClass>
19171920
query.include<any>('attribute3.someProp');
1918-
// // $ExpectError todo
1919-
// query.include(['attribute1', 'nonexistentProp']);
1921+
// $ExpectError
1922+
query.include(['attribute1', 'nonexistentProp']);
1923+
1924+
// $ExpectType ParseQuery<MySubClass>
1925+
query.exclude('attribute1', 'attribute2');
1926+
// $ExpectType ParseQuery<MySubClass>
1927+
query.exclude(['attribute1', 'attribute2']);
1928+
// $ExpectError
1929+
query.exclude('attribute1', 'nonexistentProp');
19201930

19211931
// $ExpectType ParseQuery<MySubClass>
19221932
query.lessThan('attribute2', 1000);
@@ -1975,14 +1985,23 @@ function testQuery() {
19751985

19761986
// $ExpectType ParseQuery<MySubClass>
19771987
query.select('attribute1', 'attribute2');
1978-
// // $ExpectError todo
1979-
// query.select('attribute1', 'nonexistentProp');
1988+
// $ExpectType ParseQuery<MySubClass>
1989+
query.select(['attribute1', 'attribute2']);
1990+
// $ExpectError
1991+
query.select('attribute1', 'nonexistentProp');
19801992

19811993
// $ExpectType ParseQuery<MySubClass>
19821994
query.startsWith('attribute1', 'prefix string');
19831995
// $ExpectError
19841996
query.startsWith('nonexistentProp', 'prefix string');
19851997

1998+
// $ExpectType ParseQuery<MySubClass>
1999+
query.watch('attribute1', 'attribute2');
2000+
// $ExpectType ParseQuery<MySubClass>
2001+
query.watch(['attribute1', 'attribute2']);
2002+
// $ExpectError
2003+
query.watch('attribute1', 'nonexistentProp');
2004+
19862005
// $ExpectType ParseQuery<MySubClass>
19872006
query.withCount(true);
19882007

@@ -2068,8 +2087,8 @@ function testSession() {
20682087
// $ExpectType ParseSession<{ example: number; }>
20692088
new Parse.Session({ example: 100 });
20702089

2071-
// // $ExpectError todo
2072-
// new Parse.Session<{ example: number }>();
2090+
// $ExpectType ParseSession<{ example: number; }>
2091+
new Parse.Session<{ example: number }>();
20732092

20742093
// $ExpectType ParseSession<{ example: number; }>
20752094
new Parse.Session<{ example: number }>({ example: 100 });
@@ -2102,8 +2121,8 @@ function testUser() {
21022121
// $ExpectType ParseUser<{ example: number; }>
21032122
new Parse.User({ example: 100 });
21042123

2105-
// // $ExpectError todo
2106-
// new Parse.User<{ example: number }>();
2124+
// $ExpectType ParseUser<{ example: number; }>
2125+
new Parse.User<{ example: number }>();
21072126

21082127
// $ExpectType ParseUser<{ example: number; }>
21092128
new Parse.User<{ example: number }>({ example: 100 });

0 commit comments

Comments
 (0)