Created
June 19, 2018 04:16
-
-
Save Bouke/25d5e234fe08ed8666c48c2ccc2de162 to your computer and use it in GitHub Desktop.
TypeScript typings for ember-ajax
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare module 'ember-ajax/ajax-request' { | |
import Ember from 'ember'; | |
import AjaxRequestMixin from 'ember-ajax/mixins/ajax-request'; | |
export default class AjaxRequest extends Ember.Object.extend(AjaxRequestMixin) { } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare module 'ember-ajax/errors' { | |
import Ember from 'ember'; | |
class AjaxError extends Ember.Error { } | |
class InvalidError extends AjaxError { } | |
class UnauthorizedError extends AjaxError { } | |
class ForbiddenError extends AjaxError { } | |
class BadRequestError extends AjaxError { } | |
class NotFoundError extends AjaxError { } | |
class TimeoutError extends AjaxError { } | |
class AbortError extends AjaxError { } | |
class ConflictError extends AjaxError { } | |
class ServerError extends AjaxError { } | |
function isAjaxError(error: Error): boolean | |
function isUnauthorizedError(error: number | Error): boolean | |
function isForbiddenError(error: number | Error): boolean | |
function isInvalidError(error: number | Error): boolean | |
function isBadRequestError(error: number | Error): boolean | |
function isNotFoundError(error: number | Error): boolean | |
function isTimeoutError(error: number | Error): boolean | |
function isAbortError(error: number | Error): boolean | |
function isConflictError(error: number | Error): boolean | |
function isServerError(error: number | Error): boolean | |
function isSuccess(error: number): boolean | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare module 'ember-ajax/mixins/ajax-request' { | |
import Ember from 'ember'; | |
import RSVP from 'rsvp'; | |
import { AjaxError } from 'ember-ajax/errors'; | |
import * as jQuery from 'jquery'; | |
interface AjaxRequestMixin { | |
namespace?: string; | |
contentType: string; | |
headers: JQuery.PlainObject | Ember.ComputedProperty<JQuery.PlainObject>; | |
request(url: string, options?: JQuery.AjaxSettings): RSVP.Promise<any>; | |
request<T>(url: string, options?: JQuery.AjaxSettings): RSVP.Promise<T>; | |
raw(url: string, options?: JQuery.AjaxSettings): JQuery.jqXHR; | |
post(url: string, options?: JQuery.AjaxSettings): RSVP.Promise<any>; | |
post<T>(url: string, options?: JQuery.AjaxSettings): RSVP.Promise<T>; | |
put(url: string, options?: JQuery.AjaxSettings): RSVP.Promise<any>; | |
put<T>(url: string, options?: JQuery.AjaxSettings): RSVP.Promise<T>; | |
patch(url: string, options?: JQuery.AjaxSettings): RSVP.Promise<any>; | |
patch<T>(url: string, options?: JQuery.AjaxSettings): RSVP.Promise<T>; | |
del(url: string, options?: JQuery.AjaxSettings): RSVP.Promise<any>; | |
del<T>(url: string, options?: JQuery.AjaxSettings): RSVP.Promise<T>; | |
delete(url: string, options?: JQuery.AjaxSettings): RSVP.Promise<any>; | |
delete<T>(url: string, options?: JQuery.AjaxSettings): RSVP.Promise<T>; | |
get(url: string, options?: JQuery.AjaxSettings): RSVP.Promise<any>; | |
get<T>(url: string, options?: JQuery.AjaxSettings): RSVP.Promise<T>; | |
options(url: string, options?: JQuery.AjaxSettings): JQuery.AjaxSettings; | |
handleResponse<T>(status: number, headers: Headers, payload: T, requestData: JQuery.AjaxSettings): T | AjaxError; | |
generateDetailedMessage(status: number, headers: Headers, payload: any, requestData: JQuery.AjaxSettings): string; | |
parseErrorResponse(responseText: string): any; | |
normalizeErrorResponse<T>(status: number, headers: Headers, payload: T): T; | |
isUnauthorizedError(status: number): boolean; | |
isForbiddenError(status: number): boolean; | |
isInvalidError(status: number): boolean; | |
isBadRequestError(status: number): boolean; | |
isNotFoundError(status: number): boolean; | |
isAbortError(status: number): boolean; | |
isConflictError(status: number): boolean; | |
isServerError(status: number): boolean; | |
isSuccess(status: number): boolean; | |
} | |
const AjaxRequestMixin: Ember.Mixin<AjaxRequestMixin>; | |
export default AjaxRequestMixin; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare module 'ember-ajax/mixins/ajax-support' { | |
import Ember from 'ember'; | |
interface AjaxSupportMixin { | |
} | |
const AjaxSupportMixin: Ember.Mixin<AjaxSupportMixin>; | |
export default AjaxSupportMixin; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare module 'ember-ajax/request' { | |
import RSVP from 'rsvp'; | |
import AjaxRequest from 'ember-ajax/ajax-request'; | |
import * as jQuery from 'jquery'; | |
function request(url: string, options?: JQuery.AjaxSettings): RSVP.Promise<any>; | |
function request<T>(url: string, options?: JQuery.AjaxSettings): RSVP.Promise<T>; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare module 'ember-ajax/services/ajax' { | |
import Ember from 'ember'; | |
import Service from '@ember/service'; | |
import AjaxRequestMixin from 'ember-ajax/mixins/ajax-request'; | |
export default class AjaxService extends Service.extend(AjaxRequestMixin) { } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for posting this! These definitions are probably good enough for most cases, although most of the
RSVP.Promise
here are actually a customPromise
subclass that maintains a reference to this weird.xhr
property that exposes the underlying jQuery XHR object, which some people asked for, since it allows you to listen for progress events and stuff like that.