diff --git a/types/parse/index.d.ts b/types/parse/index.d.ts index ec130f8ffe..e839515d79 100644 --- a/types/parse/index.d.ts +++ b/types/parse/index.d.ts @@ -1,6 +1,6 @@ -// Type definitions for Parse v1.2.19 +// Type definitions for parse v1.9.2 // Project: https://parse.com/ -// Definitions by: Ullisen Media Group +// Definitions by: Ullisen Media Group , David Poetzsch-Heffter // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// @@ -10,8 +10,8 @@ declare namespace Parse { var applicationId: string; - var javaScriptKey: string; - var masterKey: string; + var javaScriptKey: string | undefined; + var masterKey: string | undefined; var serverURL: string; var VERSION: string; @@ -82,7 +82,7 @@ declare namespace Parse { class Promise implements IPromise { static as(resolvedValue: U): Promise; - static error(error: U): Promise; + static error(error: any): Promise; static is(possiblePromise: any): Boolean; static when(promises: IPromise[]): Promise; static when(...promises: IPromise[]): Promise; @@ -191,7 +191,7 @@ declare namespace Parse { constructor(name: string, data: any, type?: string); name(): string; url(): string; - save(options?: SuccessFailureOptions): Promise; + save(options?: SuccessFailureOptions): Promise; } @@ -326,28 +326,28 @@ declare namespace Parse { constructor(attributes?: string[], options?: any); static extend(className: string, protoProps?: any, classProps?: any): any; - static fetchAll(list: Object[], options: SuccessFailureOptions): Promise; - static fetchAllIfNeeded(list: Object[], options: SuccessFailureOptions): Promise; - static destroyAll(list: Object[], options?: Object.DestroyAllOptions): Promise; + static fetchAll(list: T[], options: SuccessFailureOptions): Promise; + static fetchAllIfNeeded(list: T[], options: SuccessFailureOptions): Promise; + static destroyAll(list: T[], options?: Object.DestroyAllOptions): Promise; static saveAll(list: T[], options?: Object.SaveAllOptions): Promise; static registerSubclass(className: string, clazz: new (options?: any) => T): void; initialize(): void; - add(attr: string, item: any): Object; + add(attr: string, item: any): this; addUnique(attr: string, item: any): any; - change(options: any): Object; + change(options: any): this; changedAttributes(diff: any): boolean; clear(options: any): any; - clone(): Object; - destroy(options?: Object.DestroyOptions): Promise; + clone(): this; + destroy(options?: Object.DestroyOptions): Promise; dirty(attr: String): boolean; dirtyKeys(): string[]; escape(attr: string): string; existed(): boolean; - fetch(options?: Object.FetchOptions): Promise; - get(attr: string): any; - getACL(): ACL; + fetch(options?: Object.FetchOptions): Promise; + get(attr: string): any | undefined; + getACL(): ACL | undefined; has(attr: string): boolean; hasChanged(attr: string): boolean; increment(attr: string, amount?: number): any; @@ -357,8 +357,8 @@ declare namespace Parse { previousAttributes(): any; relation(attr: string): Relation; remove(attr: string, item: any): any; - save(attrs?: { [key: string]: any }, options?: Object.SaveOptions): Promise; - save(key: string, value: any, options?: Object.SaveOptions): Promise; + save(attrs?: { [key: string]: any } | null, options?: Object.SaveOptions): Promise; + save(key: string, value: any, options?: Object.SaveOptions): Promise; set(key: string, value: any, options?: Object.SetOptions): boolean; setACL(acl: ACL, options?: SuccessFailureOptions): boolean; unset(attr: string, options?: any): any; @@ -508,7 +508,7 @@ declare namespace Parse { static unbind(): Events; on(eventName: string, callback?: Function, context?: any): Events; - off(eventName?: string, callback?: Function, context?: any): Events; + off(eventName?: string | null, callback?: Function | null, context?: any): Events; trigger(eventName: string, ...args: any[]): Events; bind(eventName: string, callback: Function, context?: any): Events; unbind(eventName?: string, callback?: Function, context?: any): Events; @@ -576,9 +576,10 @@ declare namespace Parse { objectClass: any; className: string; - constructor(objectClass: any); + constructor(objectClass: string); + constructor(objectClass: new(...args: any[]) => Object); - static or(...var_args: Query[]): Query; + static or(...var_args: Query[]): Query; addAscending(key: string): Query; addAscending(key: string[]): Query; @@ -590,19 +591,19 @@ declare namespace Parse { containedIn(key: string, values: any[]): Query; contains(key: string, substring: string): Query; containsAll(key: string, values: any[]): Query; - count(options?: Query.CountOptions): Promise; + count(options?: Query.CountOptions): Promise; descending(key: string): Query; descending(key: string[]): Query; doesNotExist(key: string): Query; - doesNotMatchKeyInQuery(key: string, queryKey: string, query: Query): Query; - doesNotMatchQuery(key: string, query: Query): Query; - each(callback: Function, options?: Query.EachOptions): Promise; + doesNotMatchKeyInQuery(key: string, queryKey: string, query: Query): Query; + doesNotMatchQuery(key: string, query: Query): Query; + each(callback: Function, options?: Query.EachOptions): Promise; endsWith(key: string, suffix: string): Query; equalTo(key: string, value: any): Query; exists(key: string): Query; - find(options?: Query.FindOptions): Promise; - first(options?: Query.FirstOptions): Promise; - get(objectId: string, options?: Query.GetOptions): Promise; + find(options?: Query.FindOptions): Promise; + first(options?: Query.FirstOptions): Promise; + get(objectId: string, options?: Query.GetOptions): Promise; greaterThan(key: string, value: any): Query; greaterThanOrEqualTo(key: string, value: any): Query; include(key: string): Query; @@ -611,8 +612,8 @@ declare namespace Parse { lessThanOrEqualTo(key: string, value: any): Query; limit(n: number): Query; matches(key: string, regex: RegExp, modifiers: any): Query; - matchesKeyInQuery(key: string, queryKey: string, query: Query): Query; - matchesQuery(key: string, query: Query): Query; + matchesKeyInQuery(key: string, queryKey: string, query: Query): Query; + matchesQuery(key: string, query: Query): Query; near(key: string, point: GeoPoint): Query; notContainedIn(key: string, values: any[]): Query; notEqualTo(key: string, value: any): Query; @@ -720,24 +721,24 @@ declare namespace Parse { */ class User extends Object { - static current(): User; - static signUp(username: string, password: string, attrs: any, options?: SuccessFailureOptions): Promise; - static logIn(username: string, password: string, options?: SuccessFailureOptions): Promise; - static logOut(): Promise; + static current(): User | undefined; + static signUp(username: string, password: string, attrs: any, options?: SuccessFailureOptions): Promise; + static logIn(username: string, password: string, options?: SuccessFailureOptions): Promise; + static logOut(): Promise; static allowCustomUserClass(isAllowed: boolean): void; - static become(sessionToken: string, options?: SuccessFailureOptions): Promise; - static requestPasswordReset(email: string, options?: SuccessFailureOptions): Promise; + static become(sessionToken: string, options?: SuccessFailureOptions): Promise; + static requestPasswordReset(email: string, options?: SuccessFailureOptions): Promise; static extend(protoProps?: any, classProps?: any): any; - signUp(attrs: any, options?: SuccessFailureOptions): Promise; - logIn(options?: SuccessFailureOptions): Promise; + signUp(attrs: any, options?: SuccessFailureOptions): Promise; + logIn(options?: SuccessFailureOptions): Promise; authenticated(): boolean; isCurrent(): boolean; - getEmail(): string; - setEmail(email: string, options: SuccessFailureOptions): boolean; + getEmail(): string | undefined; + setEmail(email: string, options?: SuccessFailureOptions): boolean; - getUsername(): string; + getUsername(): string | undefined; setUsername(username: string, options?: SuccessFailureOptions): boolean; setPassword(password: string, options?: SuccessFailureOptions): boolean; @@ -801,7 +802,7 @@ declare namespace Parse { namespace Analytics { - function track(name: string, dimensions: any):Promise; + function track(name: string, dimensions: any): Promise; } /** @@ -863,8 +864,8 @@ declare namespace Parse { } interface FunctionResponse { - success?: (response: any) => void; - error?: (response: any) => void; + success: (response: any) => void; + error: (response: any) => void; } interface Cookie { @@ -883,7 +884,7 @@ declare namespace Parse { interface BeforeDeleteResponse extends FunctionResponse {} interface BeforeSaveRequest extends SaveRequest {} interface BeforeSaveResponse extends FunctionResponse { - success?: () => void; + success: () => void; } function afterDelete(arg1: any, func?: (request: AfterDeleteRequest) => void): void; @@ -893,7 +894,7 @@ declare namespace Parse { function define(name: string, func?: (request: FunctionRequest, response: FunctionResponse) => void): void; function httpRequest(options: HTTPOptions): Promise; function job(name: string, func?: (request: JobRequest, status: JobStatus) => void): HttpResponse; - function run(name: string, data?: any, options?: RunOptions): Promise; + function run(name: string, data?: any, options?: RunOptions): Promise; function useMasterKey(): void; interface RunOptions extends SuccessFailureOptions, ScopeOptions { } @@ -904,7 +905,7 @@ declare namespace Parse { * import Buffer = require("buffer").Buffer; */ var HTTPOptions: new () => HTTPOptions; - interface HTTPOptions extends FunctionResponse { + interface HTTPOptions { /** * The body of the request. * If it is a JSON object, then the Content-Type set in the headers must be application/x-www-form-urlencoded or application/json. @@ -934,6 +935,9 @@ declare namespace Parse { * The url to send the request to. */ url: string; + + success?: (response: any) => void; + error?: (response: any) => void; } } diff --git a/types/parse/parse-tests.ts b/types/parse/parse-tests.ts index 7e6c163913..36dc7cb334 100644 --- a/types/parse/parse-tests.ts +++ b/types/parse/parse-tests.ts @@ -37,6 +37,8 @@ function test_object() { var game = new Game(); + game.fetch((g: Game) => {}); + // Create a new instance of that class. var gameScore = new GameScore(); @@ -212,6 +214,10 @@ function test_analytics() { Parse.Analytics.track('error', { code: codeString }) } +function test_relation() { + new Parse.User().relation("games").query().find().then((g: Game[]) => {}); +} + function test_user_acl_roles() { var user = new Parse.User(); @@ -238,11 +244,12 @@ function test_user_acl_roles() { var game = new Game(); game.set("score", new GameScore()); game.setACL(new Parse.ACL(Parse.User.current())); - game.save(); + game.save().then((game: Game) => {}); + game.save(null, { useMasterKey: true }); var groupACL = new Parse.ACL(); - var userList: Parse.User[] = [Parse.User.current()]; + var userList: Parse.User[] = [Parse.User.current()!]; // userList is an array with the users we are sending this message to. for (var i = 0; i < userList.length; i++) { groupACL.setReadAccess(userList[i], true); @@ -261,7 +268,7 @@ function test_user_acl_roles() { // By specifying no write privileges for the ACL, we can ensure the role cannot be altered. var role = new Parse.Role("Administrator", groupACL); - role.getUsers().add(role); + role.getUsers().add(userList[0]); role.getRoles().add(role); role.save(); @@ -292,7 +299,7 @@ function test_facebook_util() { } }); - var user = Parse.User.current(); + var user = Parse.User.current()!; if (!Parse.FacebookUtils.isLinked(user)) { Parse.FacebookUtils.link(user, null, { @@ -342,7 +349,7 @@ function test_geo_points() { var point = new Parse.GeoPoint({latitude: 40.0, longitude: -30.0}); - var userObject = Parse.User.current(); + var userObject = Parse.User.current()!; // User's location var userGeoPoint = userObject.get("location"); @@ -357,8 +364,10 @@ function test_geo_points() { var southwestOfSF = new Parse.GeoPoint(37.708813, -122.526398); var northeastOfSF = new Parse.GeoPoint(37.822802, -122.373962); - var query = new Parse.Query(PlaceObject); - query.withinGeoBox("location", southwestOfSF, northeastOfSF); + var query2 = new Parse.Query(PlaceObject); + query2.withinGeoBox("location", southwestOfSF, northeastOfSF); + + var query3 = new Parse.Query("PlaceObject").find().then((o: Parse.Object[]) => {}); } function test_push() { diff --git a/types/parse/tsconfig.json b/types/parse/tsconfig.json index 634ca903ac..5fecdb4dd5 100644 --- a/types/parse/tsconfig.json +++ b/types/parse/tsconfig.json @@ -7,7 +7,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "baseUrl": "../", "typeRoots": [ "../" @@ -20,4 +20,4 @@ "index.d.ts", "parse-tests.ts" ] -} \ No newline at end of file +}