From 512340e39b7858d1bf7c7751714cbf69220aac84 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Tue, 11 Aug 2015 15:01:29 -0700 Subject: [PATCH] chore: Remove IRequestOptions / IResponseOptions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- modules/http/http.ts | 4 ++-- modules/http/src/base_request_options.ts | 8 ++++---- modules/http/src/base_response_options.ts | 8 ++++---- modules/http/src/http.ts | 18 +++++++++--------- modules/http/src/interfaces.ts | 4 ++-- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/modules/http/http.ts b/modules/http/http.ts index 6019609678..a12a4fbcf1 100644 --- a/modules/http/http.ts +++ b/modules/http/http.ts @@ -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'; diff --git a/modules/http/src/base_request_options.ts b/modules/http/src/base_request_options.ts index 1e49e5fac7..becfd2f9eb 100644 --- a/modules/http/src/base_request_options.ts +++ b/modules/http/src/base_request_options.ts @@ -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, diff --git a/modules/http/src/base_response_options.ts b/modules/http/src/base_response_options.ts index 20352ee405..1d7d27dc9e 100644 --- a/modules/http/src/base_response_options.ts +++ b/modules/http/src/base_response_options.ts @@ -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, diff --git a/modules/http/src/http.ts b/modules/http/src/http.ts index a5ed37cf54..eef426a2da 100644 --- a/modules/http/src/http.ts +++ b/modules/http/src/http.ts @@ -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)); diff --git a/modules/http/src/interfaces.ts b/modules/http/src/interfaces.ts index a8ed7ac3b6..6aca4d4c52 100644 --- a/modules/http/src/interfaces.ts +++ b/modules/http/src/interfaces.ts @@ -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;