Skip to content

Commit 539ba2a

Browse files
authored
refactor: Add initial generic type definitions (#2485)
1 parent 6d33b19 commit 539ba2a

31 files changed

+1136
-1075
lines changed

eslint.config.test.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ export default tseslint.config({
1414
'@typescript-eslint': tseslint.plugin,
1515
},
1616
rules: {
17-
'no-empty': 'off',
1817
'@typescript-eslint/no-unused-vars': 'off',
1918
'@typescript-eslint/no-unused-expressions': 'off',
2019
'@typescript-eslint/no-empty-object-type': 'off',
21-
'@typescript-eslint/ban-ts-comment': 'off',
2220
'@typescript-eslint/no-unsafe-call': 'off',
2321
'@typescript-eslint/no-unsafe-member-access': 'off',
2422
'@typescript-eslint/no-unsafe-argument': 'off',
2523
'@typescript-eslint/no-unsafe-assignment': 'off',
24+
"@typescript-eslint/no-explicit-any": "off",
25+
"@typescript-eslint/no-unsafe-return": "off",
2626
},
2727
languageOptions: {
2828
parser: tseslint.parser,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
"posttest:mongodb": "mongodb-runner stop --all",
107107
"lint": "eslint --cache src/ integration/",
108108
"lint:fix": "eslint --fix --cache src/ integration/",
109-
"test:types": "eslint --cache types/tests.ts -c eslint.config.test.mjs",
109+
"test:types": "eslint types/tests.ts -c eslint.config.test.mjs",
110110
"watch": "cross-env PARSE_BUILD=${PARSE_BUILD} gulp watch",
111111
"watch:browser": "cross-env PARSE_BUILD=browser npm run watch",
112112
"watch:node": "cross-env PARSE_BUILD=node npm run watch",

src/AnonymousUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const AnonymousUtils = {
4444
* linked to an anonymous user.
4545
* @static
4646
*/
47-
isLinked(user: ParseUser) {
47+
isLinked(user: ParseUser): boolean {
4848
const provider = this._getAuthProvider();
4949
return user._isLinked(provider.getAuthType());
5050
},

src/CoreManager.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import type ParseSession from './ParseSession';
1313
import type { HookDeclaration, HookDeleteArg } from './ParseHooks';
1414
import type ParseConfig from './ParseConfig';
1515
import type LiveQueryClient from './LiveQueryClient';
16-
import type ParseSchema from './ParseSchema';
1716
import type ParseInstallation from './ParseInstallation';
1817

1918
type AnalyticsController = {
@@ -119,7 +118,7 @@ type RESTController = {
119118
};
120119
type SchemaController = {
121120
purge: (className: string) => Promise<any>;
122-
get: (className: string, options?: RequestOptions) => Promise<{ results: ParseSchema[] }>;
121+
get: (className: string, options?: RequestOptions) => Promise<any>;
123122
delete: (className: string, options?: RequestOptions) => Promise<void>;
124123
create: (className: string, params: any, options?: RequestOptions) => Promise<any>;
125124
update: (className: string, params: any, options?: RequestOptions) => Promise<any>;

src/FacebookUtils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/* global FB */
22
import ParseUser from './ParseUser';
3-
import type { AuthProviderType } from './ParseUser';
3+
import type { AuthProvider } from './ParseUser';
44

55
let initialized = false;
66
let requestedPermissions;
77
let initOptions;
8-
const provider: AuthProviderType = {
8+
const provider: AuthProvider = {
99
authenticate(options) {
1010
if (typeof FB === 'undefined') {
1111
options.error(this, 'Facebook SDK not found.');
@@ -227,7 +227,7 @@ const FacebookUtils = {
227227
},
228228

229229
// Used for testing purposes
230-
_getAuthProvider() {
230+
_getAuthProvider(): AuthProvider {
231231
return provider;
232232
},
233233
};

src/LiveQuerySubscription.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ import type ParseQuery from './ParseQuery';
8484
*
8585
* });</pre></p>
8686
*/
87-
class Subscription {
87+
class LiveQuerySubscription {
8888
id: string | number;
8989
query: ParseQuery;
9090
sessionToken?: string;
@@ -131,4 +131,4 @@ class Subscription {
131131
}
132132
}
133133

134-
export default Subscription;
134+
export default LiveQuerySubscription;

src/ParseACL.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ class ParseACL {
2525
permissionsById: ByIdMap;
2626

2727
/**
28-
* @param {(Parse.User | object)} arg1 The user to initialize the ACL for
28+
* @param {(Parse.User | object | null)} arg1 The user to initialize the ACL for
2929
*/
30-
constructor(arg1: ParseUser | ByIdMap) {
30+
constructor(arg1?: ParseUser | ByIdMap | null) {
3131
this.permissionsById = {};
3232
if (arg1 && typeof arg1 === 'object') {
3333
const ParseUser = CoreManager.getParseUser();

src/ParseGeoPoint.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ParseGeoPoint {
3131
* @param {number} arg2 The longitude of the GeoPoint
3232
*/
3333
constructor(
34-
arg1: Array<number> | { latitude: number; longitude: number } | number,
34+
arg1?: Array<number> | { latitude: number; longitude: number } | number,
3535
arg2?: number
3636
) {
3737
if (Array.isArray(arg1)) {

src/ParseInstallation.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import CoreManager from './CoreManager';
22
import ParseError from './ParseError';
3-
import ParseObject from './ParseObject';
4-
5-
import type { AttributeMap } from './ObjectStateMutations';
3+
import ParseObject, { Attributes } from './ParseObject';
64

75
type DeviceInterface = {
86
IOS: string;
@@ -33,11 +31,11 @@ const DEVICE_TYPES: DeviceInterface = {
3331
*
3432
* @alias Parse.Installation
3533
*/
36-
class ParseInstallation extends ParseObject {
34+
class ParseInstallation<T extends Attributes = Attributes> extends ParseObject<T> {
3735
/**
3836
* @param {object} attributes The initial set of data to store in the object.
3937
*/
40-
constructor(attributes?: AttributeMap) {
38+
constructor(attributes?: T) {
4139
super('_Installation');
4240
if (attributes && typeof attributes === 'object') {
4341
try {
@@ -220,7 +218,7 @@ class ParseInstallation extends ParseObject {
220218
* @param {...any} args
221219
* @returns {Promise}
222220
*/
223-
async fetch(...args: Array<any>): Promise<ParseInstallation> {
221+
async fetch(...args: Array<any>): Promise<this> {
224222
try {
225223
await super.fetch.apply(this, args);
226224
} catch (e) {
@@ -259,7 +257,7 @@ class ParseInstallation extends ParseObject {
259257
this._markAllFieldsDirty();
260258
await super.save.apply(this, args);
261259
}
262-
await CoreManager.getInstallationController().updateInstallationOnDisk(this);
260+
await CoreManager.getInstallationController().updateInstallationOnDisk(this as any);
263261
return this;
264262
}
265263

0 commit comments

Comments
 (0)