Skip to content

refactor: Add initial generic type definitions #2485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 8, 2025
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
4 changes: 2 additions & 2 deletions eslint.config.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ export default tseslint.config({
'@typescript-eslint': tseslint.plugin,
},
rules: {
'no-empty': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-unused-expressions': 'off',
'@typescript-eslint/no-empty-object-type': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unsafe-return": "off",
},
languageOptions: {
parser: tseslint.parser,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
"posttest:mongodb": "mongodb-runner stop --all",
"lint": "eslint --cache src/ integration/",
"lint:fix": "eslint --fix --cache src/ integration/",
"test:types": "eslint --cache types/tests.ts -c eslint.config.test.mjs",
"test:types": "eslint types/tests.ts -c eslint.config.test.mjs",
"watch": "cross-env PARSE_BUILD=${PARSE_BUILD} gulp watch",
"watch:browser": "cross-env PARSE_BUILD=browser npm run watch",
"watch:node": "cross-env PARSE_BUILD=node npm run watch",
Expand Down
2 changes: 1 addition & 1 deletion src/AnonymousUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const AnonymousUtils = {
* linked to an anonymous user.
* @static
*/
isLinked(user: ParseUser) {
isLinked(user: ParseUser): boolean {
const provider = this._getAuthProvider();
return user._isLinked(provider.getAuthType());
},
Expand Down
3 changes: 1 addition & 2 deletions src/CoreManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import type ParseSession from './ParseSession';
import type { HookDeclaration, HookDeleteArg } from './ParseHooks';
import type ParseConfig from './ParseConfig';
import type LiveQueryClient from './LiveQueryClient';
import type ParseSchema from './ParseSchema';
import type ParseInstallation from './ParseInstallation';

type AnalyticsController = {
Expand Down Expand Up @@ -119,7 +118,7 @@ type RESTController = {
};
type SchemaController = {
purge: (className: string) => Promise<any>;
get: (className: string, options?: RequestOptions) => Promise<{ results: ParseSchema[] }>;
get: (className: string, options?: RequestOptions) => Promise<any>;
delete: (className: string, options?: RequestOptions) => Promise<void>;
create: (className: string, params: any, options?: RequestOptions) => Promise<any>;
update: (className: string, params: any, options?: RequestOptions) => Promise<any>;
Expand Down
6 changes: 3 additions & 3 deletions src/FacebookUtils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* global FB */
import ParseUser from './ParseUser';
import type { AuthProviderType } from './ParseUser';
import type { AuthProvider } from './ParseUser';

let initialized = false;
let requestedPermissions;
let initOptions;
const provider: AuthProviderType = {
const provider: AuthProvider = {
authenticate(options) {
if (typeof FB === 'undefined') {
options.error(this, 'Facebook SDK not found.');
Expand Down Expand Up @@ -227,7 +227,7 @@ const FacebookUtils = {
},

// Used for testing purposes
_getAuthProvider() {
_getAuthProvider(): AuthProvider {
return provider;
},
};
Expand Down
4 changes: 2 additions & 2 deletions src/LiveQuerySubscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ import type ParseQuery from './ParseQuery';
*
* });</pre></p>
*/
class Subscription {
class LiveQuerySubscription {
id: string | number;
query: ParseQuery;
sessionToken?: string;
Expand Down Expand Up @@ -131,4 +131,4 @@ class Subscription {
}
}

export default Subscription;
export default LiveQuerySubscription;
4 changes: 2 additions & 2 deletions src/ParseACL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class ParseACL {
permissionsById: ByIdMap;

/**
* @param {(Parse.User | object)} arg1 The user to initialize the ACL for
* @param {(Parse.User | object | null)} arg1 The user to initialize the ACL for
*/
constructor(arg1: ParseUser | ByIdMap) {
constructor(arg1?: ParseUser | ByIdMap | null) {
this.permissionsById = {};
if (arg1 && typeof arg1 === 'object') {
const ParseUser = CoreManager.getParseUser();
Expand Down
2 changes: 1 addition & 1 deletion src/ParseGeoPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ParseGeoPoint {
* @param {number} arg2 The longitude of the GeoPoint
*/
constructor(
arg1: Array<number> | { latitude: number; longitude: number } | number,
arg1?: Array<number> | { latitude: number; longitude: number } | number,
arg2?: number
) {
if (Array.isArray(arg1)) {
Expand Down
12 changes: 5 additions & 7 deletions src/ParseInstallation.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import CoreManager from './CoreManager';
import ParseError from './ParseError';
import ParseObject from './ParseObject';

import type { AttributeMap } from './ObjectStateMutations';
import ParseObject, { Attributes } from './ParseObject';

type DeviceInterface = {
IOS: string;
Expand Down Expand Up @@ -33,11 +31,11 @@ const DEVICE_TYPES: DeviceInterface = {
*
* @alias Parse.Installation
*/
class ParseInstallation extends ParseObject {
class ParseInstallation<T extends Attributes = Attributes> extends ParseObject<T> {
/**
* @param {object} attributes The initial set of data to store in the object.
*/
constructor(attributes?: AttributeMap) {
constructor(attributes?: T) {
super('_Installation');
if (attributes && typeof attributes === 'object') {
try {
Expand Down Expand Up @@ -220,7 +218,7 @@ class ParseInstallation extends ParseObject {
* @param {...any} args
* @returns {Promise}
*/
async fetch(...args: Array<any>): Promise<ParseInstallation> {
async fetch(...args: Array<any>): Promise<this> {
try {
await super.fetch.apply(this, args);
} catch (e) {
Expand Down Expand Up @@ -259,7 +257,7 @@ class ParseInstallation extends ParseObject {
this._markAllFieldsDirty();
await super.save.apply(this, args);
}
await CoreManager.getInstallationController().updateInstallationOnDisk(this);
await CoreManager.getInstallationController().updateInstallationOnDisk(this as any);
return this;
}

Expand Down
Loading