chore: Remove IRequestOptions / IResponseOptions
BREAKING CHANGE: Reasons: 1) Interfaces should not start with letter ‘I’ 2) Interfaces do not help with mistype properties, but literal types do. - https://github.com/Microsoft/TypeScript/pull/3823 - https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#strict-object-literal-assignment-checking
This commit is contained in:
parent
284dc67076
commit
512340e39b
|
@ -19,8 +19,8 @@ export {Request} from 'http/src/static_request';
|
|||
export {Response} from 'http/src/static_response';
|
||||
|
||||
export {
|
||||
IRequestOptions,
|
||||
IResponseOptions,
|
||||
RequestOptionsArgs,
|
||||
ResponseOptionsArgs,
|
||||
Connection,
|
||||
ConnectionBackend
|
||||
} from 'http/src/interfaces';
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import {CONST_EXPR, CONST, isPresent, isString} from 'angular2/src/facade/lang';
|
||||
import {Headers} from './headers';
|
||||
import {RequestModesOpts, RequestMethods, RequestCacheOpts, RequestCredentialsOpts} from './enums';
|
||||
import {IRequestOptions} from './interfaces';
|
||||
import {RequestOptionsArgs} from './interfaces';
|
||||
import {Injectable} from 'angular2/di';
|
||||
import {URLSearchParams} from './url_search_params';
|
||||
|
||||
|
@ -13,7 +13,7 @@ import {URLSearchParams} from './url_search_params';
|
|||
*
|
||||
* All values are null by default.
|
||||
*/
|
||||
export class RequestOptions implements IRequestOptions {
|
||||
export class RequestOptions {
|
||||
/**
|
||||
* Http method with which to execute the request.
|
||||
*
|
||||
|
@ -36,7 +36,7 @@ export class RequestOptions implements IRequestOptions {
|
|||
url: string;
|
||||
search: URLSearchParams;
|
||||
constructor({method, headers, body, mode, credentials, cache, url, search}:
|
||||
IRequestOptions = {}) {
|
||||
RequestOptionsArgs = {}) {
|
||||
this.method = isPresent(method) ? method : null;
|
||||
this.headers = isPresent(headers) ? headers : null;
|
||||
this.body = isPresent(body) ? body : null;
|
||||
|
@ -53,7 +53,7 @@ export class RequestOptions implements IRequestOptions {
|
|||
* Creates a copy of the `RequestOptions` instance, using the optional input as values to override
|
||||
* existing values.
|
||||
*/
|
||||
merge(options?: IRequestOptions): RequestOptions {
|
||||
merge(options?: RequestOptionsArgs): RequestOptions {
|
||||
return new RequestOptions({
|
||||
method: isPresent(options) && isPresent(options.method) ? options.method : this.method,
|
||||
headers: isPresent(options) && isPresent(options.headers) ? options.headers : this.headers,
|
||||
|
|
|
@ -2,7 +2,7 @@ import {Injectable} from 'angular2/di';
|
|||
import {isPresent, isJsObject} from 'angular2/src/facade/lang';
|
||||
import {Headers} from './headers';
|
||||
import {ResponseTypes} from './enums';
|
||||
import {IResponseOptions} from './interfaces';
|
||||
import {ResponseOptionsArgs} from './interfaces';
|
||||
|
||||
/**
|
||||
* Creates a response options object similar to the
|
||||
|
@ -13,7 +13,7 @@ import {IResponseOptions} from './interfaces';
|
|||
*
|
||||
* All values are null by default.
|
||||
*/
|
||||
export class ResponseOptions implements IResponseOptions {
|
||||
export class ResponseOptions {
|
||||
// TODO: ArrayBuffer | FormData | Blob
|
||||
body: string | Object;
|
||||
status: number;
|
||||
|
@ -21,7 +21,7 @@ export class ResponseOptions implements IResponseOptions {
|
|||
statusText: string;
|
||||
type: ResponseTypes;
|
||||
url: string;
|
||||
constructor({body, status, headers, statusText, type, url}: IResponseOptions = {}) {
|
||||
constructor({body, status, headers, statusText, type, url}: ResponseOptionsArgs = {}) {
|
||||
this.body = isPresent(body) ? body : null;
|
||||
this.status = isPresent(status) ? status : null;
|
||||
this.headers = isPresent(headers) ? headers : null;
|
||||
|
@ -30,7 +30,7 @@ export class ResponseOptions implements IResponseOptions {
|
|||
this.url = isPresent(url) ? url : null;
|
||||
}
|
||||
|
||||
merge(options?: IResponseOptions): ResponseOptions {
|
||||
merge(options?: ResponseOptionsArgs): ResponseOptions {
|
||||
return new ResponseOptions({
|
||||
body: isPresent(options) && isPresent(options.body) ? options.body : this.body,
|
||||
status: isPresent(options) && isPresent(options.status) ? options.status : this.status,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import {isString, isPresent, isBlank, makeTypeError} from 'angular2/src/facade/lang';
|
||||
import {Injectable} from 'angular2/src/di/decorators';
|
||||
import {IRequestOptions, Connection, ConnectionBackend} from './interfaces';
|
||||
import {RequestOptionsArgs, Connection, ConnectionBackend} from './interfaces';
|
||||
import {Request} from './static_request';
|
||||
import {BaseRequestOptions, RequestOptions} from './base_request_options';
|
||||
import {RequestMethods} from './enums';
|
||||
|
@ -111,7 +111,7 @@ export class Http {
|
|||
* object can be provided as the 2nd argument. The options object will be merged with the values
|
||||
* of {@link BaseRequestOptions} before performing the request.
|
||||
*/
|
||||
request(url: string | Request, options?: IRequestOptions): EventEmitter {
|
||||
request(url: string | Request, options?: RequestOptionsArgs): EventEmitter {
|
||||
var responseObservable: EventEmitter;
|
||||
if (isString(url)) {
|
||||
responseObservable = httpRequest(
|
||||
|
@ -126,7 +126,7 @@ export class Http {
|
|||
/**
|
||||
* Performs a request with `get` http method.
|
||||
*/
|
||||
get(url: string, options?: IRequestOptions): EventEmitter {
|
||||
get(url: string, options?: RequestOptionsArgs): EventEmitter {
|
||||
return httpRequest(this._backend, new Request(mergeOptions(this._defaultOptions, options,
|
||||
RequestMethods.GET, url)));
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ export class Http {
|
|||
/**
|
||||
* Performs a request with `post` http method.
|
||||
*/
|
||||
post(url: string, body: string, options?: IRequestOptions): EventEmitter {
|
||||
post(url: string, body: string, options?: RequestOptionsArgs): EventEmitter {
|
||||
return httpRequest(
|
||||
this._backend,
|
||||
new Request(mergeOptions(this._defaultOptions.merge(new RequestOptions({body: body})),
|
||||
|
@ -144,7 +144,7 @@ export class Http {
|
|||
/**
|
||||
* Performs a request with `put` http method.
|
||||
*/
|
||||
put(url: string, body: string, options?: IRequestOptions): EventEmitter {
|
||||
put(url: string, body: string, options?: RequestOptionsArgs): EventEmitter {
|
||||
return httpRequest(
|
||||
this._backend,
|
||||
new Request(mergeOptions(this._defaultOptions.merge(new RequestOptions({body: body})),
|
||||
|
@ -154,7 +154,7 @@ export class Http {
|
|||
/**
|
||||
* Performs a request with `delete` http method.
|
||||
*/
|
||||
delete (url: string, options?: IRequestOptions): EventEmitter {
|
||||
delete (url: string, options?: RequestOptionsArgs): EventEmitter {
|
||||
return httpRequest(this._backend, new Request(mergeOptions(this._defaultOptions, options,
|
||||
RequestMethods.DELETE, url)));
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ export class Http {
|
|||
/**
|
||||
* Performs a request with `patch` http method.
|
||||
*/
|
||||
patch(url: string, body: string, options?: IRequestOptions): EventEmitter {
|
||||
patch(url: string, body: string, options?: RequestOptionsArgs): EventEmitter {
|
||||
return httpRequest(
|
||||
this._backend,
|
||||
new Request(mergeOptions(this._defaultOptions.merge(new RequestOptions({body: body})),
|
||||
|
@ -172,7 +172,7 @@ export class Http {
|
|||
/**
|
||||
* Performs a request with `head` http method.
|
||||
*/
|
||||
head(url: string, options?: IRequestOptions): EventEmitter {
|
||||
head(url: string, options?: RequestOptionsArgs): EventEmitter {
|
||||
return httpRequest(this._backend, new Request(mergeOptions(this._defaultOptions, options,
|
||||
RequestMethods.HEAD, url)));
|
||||
}
|
||||
|
@ -190,7 +190,7 @@ export class Jsonp extends Http {
|
|||
* object can be provided as the 2nd argument. The options object will be merged with the values
|
||||
* of {@link BaseRequestOptions} before performing the request.
|
||||
*/
|
||||
request(url: string | Request, options?: IRequestOptions): EventEmitter {
|
||||
request(url: string | Request, options?: RequestOptionsArgs): EventEmitter {
|
||||
var responseObservable: EventEmitter;
|
||||
if (isString(url)) {
|
||||
url = new Request(mergeOptions(this._defaultOptions, options, RequestMethods.GET, url));
|
||||
|
|
|
@ -42,7 +42,7 @@ export class Connection {
|
|||
* Interface for options to construct a Request, based on
|
||||
* [RequestInit](https://fetch.spec.whatwg.org/#requestinit) from the Fetch spec.
|
||||
*/
|
||||
export interface IRequestOptions {
|
||||
export type RequestOptionsArgs = {
|
||||
url?: string;
|
||||
method?: RequestMethods;
|
||||
search?: string | URLSearchParams;
|
||||
|
@ -58,7 +58,7 @@ export interface IRequestOptions {
|
|||
* Interface for options to construct a Response, based on
|
||||
* [ResponseInit](https://fetch.spec.whatwg.org/#responseinit) from the Fetch spec.
|
||||
*/
|
||||
export interface IResponseOptions {
|
||||
export type ResponseOptionsArgs = {
|
||||
// TODO: Support Blob, ArrayBuffer, JSON
|
||||
body?: string | Object | FormData;
|
||||
status?: number;
|
||||
|
|
Loading…
Reference in New Issue