2
0
mirror of https://github.com/tenrok/axios.git synced 2026-05-15 11:59:42 +03:00

Converting TypeScript definitions to ES2015 module syntax

This commit is contained in:
Nick Uraltsev
2016-08-09 23:17:11 -07:00
parent 8332392bfd
commit 5176dfdec5
4 changed files with 70 additions and 69 deletions
Vendored
+62 -62
View File
@@ -1,65 +1,65 @@
// Type definitions for Axios v0.8.1
// Project: https://github.com/mzabriskie/axios
declare var axios: axios.AxiosStatic
declare module axios {
interface AxiosRequestMethods {
get(url: string, config?: any): axios.Promise;
delete(url: string, config?: any): axios.Promise;
head(url: string, config?: any): axios.Promise;
post(url: string, data: any, config?: any): axios.Promise;
put(url: string, data: any, config?: any): axios.Promise;
patch(url: string, data: any, config?: any): axios.Promise;
}
interface AxiosStatic extends AxiosRequestMethods {
(options: axios.RequestOptions): axios.Promise;
create(defaultOptions?: axios.InstanceOptions): AxiosInstance;
all(iterable: any): axios.Promise;
spread(callback: any): axios.Promise;
}
interface AxiosInstance extends AxiosRequestMethods {
request(options: axios.RequestOptions): axios.Promise;
}
interface Response {
data?: any;
status?: number;
statusText?: string;
headers?: any;
config?: any;
}
interface Promise {
then(onFulfilled:(response: axios.Response) => void): axios.Promise;
catch(onRejected:(response: axios.Response) => void): axios.Promise;
}
interface InstanceOptions {
transformRequest?: (data: any) => any;
transformResponse?: (data: any) => any;
headers?: any;
timeout?: number;
withCredentials?: boolean;
responseType?: string;
xsrfCookieName?: string;
xsrfHeaderName?: string;
paramsSerializer?: (params: any) => string;
baseURL?: string;
}
interface RequestOptions extends InstanceOptions {
url: string;
method?: string;
params?: any;
data?: any;
}
export interface Thenable<V> {
then<R>(onFulfilled?: (value: V) => R | Thenable<R>, onRejected?: (reason: any) => R | Thenable<R>): Thenable<R>;
then<R>(onFulfilled?: (value: V) => R | Thenable<R>, onRejected?: (reason: any) => void): Thenable<R>;
catch<R>(onRejected?: (reason: any) => R | Thenable<R>): Thenable<R>;
}
declare module "axios" {
export = axios;
export interface AxiosDataTransformer {
(data: any): any;
}
export interface AxiosRequestConfig {
url?: string;
method?: string;
baseURL?: string;
transformRequest?: AxiosDataTransformer | AxiosDataTransformer[];
transformResponse?: AxiosDataTransformer | AxiosDataTransformer[];
headers?: any;
params?: any;
paramsSerializer?: (params: any) => string;
data?: any;
timeout?: number;
withCredentials?: boolean;
adapter?: any;
auth?: any;
responseType?: string;
xsrfCookieName?: string;
xsrfHeaderName?: string;
progress?: (progressEvent: any) => void;
maxContentLength?: number;
validateStatus?: (status: number) => boolean;
maxRedirects?: number;
httpAgent?: any;
httpsAgent?: any;
}
export interface AxiosResponse {
data: any;
status: number;
statusText: string;
headers: any;
config: AxiosRequestConfig;
}
export interface AxiosInstance {
defaults: AxiosRequestConfig;
request(config: AxiosRequestConfig): Thenable<AxiosResponse>;
get(url: string, config?: AxiosRequestConfig): Thenable<AxiosResponse>;
delete(url: string, config?: AxiosRequestConfig): Thenable<AxiosResponse>;
head(url: string, config?: AxiosRequestConfig): Thenable<AxiosResponse>;
post(url: string, data?: any, config?: AxiosRequestConfig): Thenable<AxiosResponse>;
put(url: string, data?: any, config?: AxiosRequestConfig): Thenable<AxiosResponse>;
patch(url: string, data?: any, config?: AxiosRequestConfig): Thenable<AxiosResponse>;
}
export interface AxiosStatic extends AxiosInstance {
(config: AxiosRequestConfig): Thenable<AxiosResponse>;
(url: string, config?: AxiosRequestConfig): Thenable<AxiosResponse>;
create(config?: AxiosRequestConfig): AxiosInstance;
all(iterable: any): Thenable<any>;
spread(callback: any): Thenable<any>;
}
declare const Axios: AxiosStatic;
export default Axios;
+6 -1
View File
@@ -24,7 +24,7 @@ function createInstance(defaultConfig) {
}
// Create the default instance to be exported
var axios = module.exports = createInstance();
var axios = createInstance();
// Expose Axios class to allow class inheritance
axios.Axios = Axios;
@@ -39,3 +39,8 @@ axios.all = function all(promises) {
return Promise.all(promises);
};
axios.spread = require('./helpers/spread');
module.exports = axios;
// Allow use of default import syntax in TypeScript
module.exports.default = axios;
+1 -3
View File
@@ -69,9 +69,7 @@
"browser": {
"./lib/adapters/http.js": "./lib/adapters/xhr.js"
},
"typescript": {
"definition": "./axios.d.ts"
},
"typings": "./axios.d.ts",
"dependencies": {
"follow-redirects": "0.0.7"
}
+1 -3
View File
@@ -1,6 +1,4 @@
/// <reference path="../../axios.d.ts" />
import axios = require('axios');
import axios from '../../';
axios.get('/user?ID=12345')
.then(function (response) {