Skip to content

Commit 81b6944

Browse files
authored
refactor: Convert ParseObject to TypeScript (#2128)
1 parent 3cc0aed commit 81b6944

12 files changed

+733
-709
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@ jobs:
1717
with:
1818
version: 2
1919
check-types:
20-
name: Check types
20+
name: Check Types
2121
timeout-minutes: 5
2222
runs-on: ubuntu-latest
2323
steps:
2424
- uses: actions/checkout@v3
2525
- run: npm ci
26-
- name: Check types
26+
- name: Build Types
27+
run: npm run build:types
28+
- name: Lint Types
29+
run: npm run lint:types
30+
- name: Test Types
2731
run: npm run test:types
2832
check-docs:
2933
name: Check Docs

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
"posttest:mongodb": "mongodb-runner stop --all",
108108
"lint": "eslint --cache src/ integration/",
109109
"lint:fix": "eslint --fix --cache src/ integration/",
110+
"lint:types": "dtslint types",
110111
"watch": "cross-env PARSE_BUILD=${PARSE_BUILD} gulp watch",
111112
"watch:browser": "cross-env PARSE_BUILD=browser npm run watch",
112113
"watch:node": "cross-env PARSE_BUILD=node npm run watch",

src/CoreManager.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type ObjectController = {
5353
object: ParseObject | Array<ParseObject>,
5454
forceFetch: boolean,
5555
options: RequestOptions
56-
) => Promise<any>,
56+
) => Promise<Array<ParseObject | undefined> | ParseObject | undefined>,
5757
save: (object: ParseObject | Array<ParseObject | ParseFile> | null, options: RequestOptions) => Promise<ParseObject | Array<ParseObject> | ParseFile>,
5858
destroy: (object: ParseObject | Array<ParseObject>, options: RequestOptions) => Promise<ParseObject | Array<ParseObject>>,
5959
};
@@ -86,7 +86,7 @@ type QueryController = {
8686
type EventuallyQueue = {
8787
save: (object: ParseObject, serverOptions: SaveOptions) => Promise<any>,
8888
destroy: (object: ParseObject, serverOptions: RequestOptions) => Promise<any>,
89-
poll: (ms: number) => void
89+
poll: (ms?: number) => void
9090
};
9191
type RESTController = {
9292
request: (method: string, path: string, data?: any, options?: RequestOptions) => Promise<any>,
@@ -598,39 +598,39 @@ const CoreManager = {
598598
return config['HooksController']!;
599599
},
600600

601-
setParseOp(op: ParseOp) {
601+
setParseOp(op: typeof ParseOp) {
602602
config['ParseOp'] = op;
603603
},
604604

605605
getParseOp() {
606606
return config['ParseOp']!;
607607
},
608608

609-
setParseObject(object: ParseObject) {
609+
setParseObject(object: typeof ParseObject) {
610610
config['ParseObject'] = object;
611611
},
612612

613613
getParseObject(): ParseObject {
614614
return config['ParseObject']!;
615615
},
616616

617-
setParseQuery(query: ParseQuery) {
617+
setParseQuery(query: typeof ParseQuery) {
618618
config['ParseQuery'] = query;
619619
},
620620

621-
getParseQuery() {
622-
return config['ParseQuery']!
621+
getParseQuery(): ParseQuery {
622+
return config['ParseQuery']!;
623623
},
624624

625-
setParseRole(role: ParseRole) {
625+
setParseRole(role: typeof ParseRole) {
626626
config['ParseRole'] = role;
627627
},
628628

629629
getParseRole(): ParseRole {
630630
return config['ParseRole']!;
631631
},
632632

633-
setParseUser(user: ParseUser) {
633+
setParseUser(user: typeof ParseUser) {
634634
config['ParseUser'] = user;
635635
},
636636

src/EventuallyQueue.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ const EventuallyQueue = {
303303
* @param [ms] Milliseconds to ping the server. Default 2000ms
304304
* @static
305305
*/
306-
poll(ms: number = 2000) {
306+
poll(ms?: number = 2000) {
307307
if (polling) {
308308
return;
309309
}

src/InstallationController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const InstallationController = {
4949
installationData.className = '_Installation';
5050
const current = ParseInstallation.fromJSON(installationData);
5151
currentInstallationCache = current;
52-
return current;
52+
return current as ParseInstallation;
5353
}
5454
const installationId = await this.currentInstallationId();
5555
const installation = new ParseInstallation();

src/Parse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ interface ParseType {
9191
_initialize(applicationId: string, javaScriptKey: string, masterKey?: string): void,
9292
setAsyncStorage(storage: any): void,
9393
setLocalDatastoreController(controller: any): void,
94-
getServerHealth(): Promise<any>
94+
getServerHealth(): Promise<any>,
9595

9696
applicationId: string,
9797
javaScriptKey: string,

src/ParseInstallation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class ParseInstallation extends ParseObject {
189189
* Parse.Installation.DEVICE_TYPES.WEB
190190
* </pre
191191
*
192-
* @property {Object} DEVICE_TYPES
192+
* @property {object} DEVICE_TYPES
193193
* @static
194194
*/
195195
static get DEVICE_TYPES(): DeviceInterface {
@@ -202,7 +202,7 @@ class ParseInstallation extends ParseObject {
202202
* @param {...any} args
203203
* @returns {Promise}
204204
*/
205-
async save(...args: Array<any>): Promise<ParseInstallation> {
205+
async save(...args: Array<any>): Promise<this> {
206206
await super.save.apply(this, args);
207207
await CoreManager.getInstallationController().updateInstallationOnDisk(this);
208208
return this;

0 commit comments

Comments
 (0)