From 5e3ccbcea9585433f36f12fc5cb2158d34723388 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Fri, 17 Jun 2016 10:57:32 -0700 Subject: [PATCH] refactor: add types (#9288) --- .../forms-deprecated/form_builder_spec.ts | 4 +-- .../test/forms-deprecated/integration_spec.ts | 4 +-- .../common/test/pipes/async_pipe_spec.ts | 8 ++--- .../common/test/pipes/date_pipe_spec.ts | 29 +++++++++---------- .../test/pipes/i18n_plural_pipe_spec.ts | 7 ++--- .../test/pipes/i18n_select_pipe_spec.ts | 7 ++--- .../common/test/pipes/json_pipe_spec.ts | 10 +++---- .../common/test/pipes/lowercase_pipe_spec.ts | 8 ++--- .../common/test/pipes/number_pipe_spec.ts | 6 ++-- .../common/test/pipes/replace_pipe_spec.ts | 18 ++++++------ .../common/test/pipes/slice_pipe_spec.ts | 19 +++++------- .../common/test/pipes/uppercase_pipe_spec.ts | 8 ++--- modules/@angular/facade/src/browser.ts | 2 +- modules/@angular/facade/src/intl.ts | 8 ++--- 14 files changed, 66 insertions(+), 72 deletions(-) diff --git a/modules/@angular/common/test/forms-deprecated/form_builder_spec.ts b/modules/@angular/common/test/forms-deprecated/form_builder_spec.ts index 443ace1abe..7bb628ea8c 100644 --- a/modules/@angular/common/test/forms-deprecated/form_builder_spec.ts +++ b/modules/@angular/common/test/forms-deprecated/form_builder_spec.ts @@ -4,8 +4,8 @@ import {afterEach, beforeEach, ddescribe, describe, expect, iit, it, xit} from ' import {PromiseWrapper} from '../../src/facade/promise'; export function main() { - function syncValidator(_: any /** TODO #9100 */): any /** TODO #9100 */ { return null; } - function asyncValidator(_: any /** TODO #9100 */) { return PromiseWrapper.resolve(null); } + function syncValidator(_: any): any { return null; } + function asyncValidator(_: any) { return PromiseWrapper.resolve(null); } describe('Form Builder', () => { var b: any /** TODO #9100 */; diff --git a/modules/@angular/common/test/forms-deprecated/integration_spec.ts b/modules/@angular/common/test/forms-deprecated/integration_spec.ts index 35b089bfcb..bc110d9530 100644 --- a/modules/@angular/common/test/forms-deprecated/integration_spec.ts +++ b/modules/@angular/common/test/forms-deprecated/integration_spec.ts @@ -561,7 +561,7 @@ export function main() { `; - var fixture: any /** TODO #9100 */; + var fixture: ComponentFixture; tcb.overrideTemplate(MyComp8, t) .createAsync(MyComp8) .then((compFixture) => fixture = compFixture); @@ -952,7 +952,7 @@ export function main() { `; - var fixture: any /** TODO #9100 */; + var fixture: ComponentFixture; tcb.overrideTemplate(MyComp8, t).createAsync(MyComp8).then((root) => fixture = root); tick(); diff --git a/modules/@angular/common/test/pipes/async_pipe_spec.ts b/modules/@angular/common/test/pipes/async_pipe_spec.ts index e89537a2a9..1d879df1dd 100644 --- a/modules/@angular/common/test/pipes/async_pipe_spec.ts +++ b/modules/@angular/common/test/pipes/async_pipe_spec.ts @@ -13,10 +13,10 @@ export function main() { describe('AsyncPipe', () => { describe('Observable', () => { - var emitter: any /** TODO #9100 */; - var pipe: any /** TODO #9100 */; - var ref: any /** TODO #9100 */; - var message = new Object(); + var emitter: EventEmitter; + var pipe: AsyncPipe; + var ref: any; + var message = {}; beforeEach(() => { emitter = new EventEmitter(); diff --git a/modules/@angular/common/test/pipes/date_pipe_spec.ts b/modules/@angular/common/test/pipes/date_pipe_spec.ts index cbbf0ed167..c3b3053e68 100644 --- a/modules/@angular/common/test/pipes/date_pipe_spec.ts +++ b/modules/@angular/common/test/pipes/date_pipe_spec.ts @@ -7,8 +7,8 @@ import {DateWrapper} from '../../src/facade/lang'; export function main() { describe('DatePipe', () => { - var date: any /** TODO #9100 */; - var pipe: any /** TODO #9100 */; + var date: Date; + var pipe: DatePipe; beforeEach(() => { date = DateWrapper.create(2015, 6, 15, 21, 43, 11); @@ -18,22 +18,21 @@ export function main() { it('should be marked as pure', () => { expect(new PipeResolver().resolve(DatePipe).pure).toEqual(true); }); - describe('supports', () => { - it('should support date', () => { expect(pipe.supports(date)).toBe(true); }); - it('should support int', () => { expect(pipe.supports(123456789)).toBe(true); }); - it('should support ISO string', - () => { expect(pipe.supports('2015-06-15T21:43:11Z')).toBe(true); }); - - it('should not support other objects', () => { - expect(pipe.supports(new Object())).toBe(false); - expect(pipe.supports(null)).toBe(false); - expect(pipe.supports('')).toBe(false); - }); - }); - // TODO(mlaval): enable tests when Intl API is no longer used, see // https://github.com/angular/angular/issues/3333 if (browserDetection.supportsIntlApi) { + describe('supports', () => { + it('should support date', () => { expect(() => pipe.transform(date)).not.toThrow(); }); + it('should support int', () => { expect(() => pipe.transform(123456789)).not.toThrow(); }); + it('should support ISO string', + () => { expect(() => pipe.transform('2015-06-15T21:43:11Z')).not.toThrow(); }); + + it('should not support other objects', () => { + expect(() => pipe.transform({})).toThrow(); + expect(() => pipe.transform('')).toThrow(); + }); + }); + describe('transform', () => { it('should format each component correctly', () => { expect(pipe.transform(date, 'y')).toEqual('2015'); diff --git a/modules/@angular/common/test/pipes/i18n_plural_pipe_spec.ts b/modules/@angular/common/test/pipes/i18n_plural_pipe_spec.ts index 9435287f5e..eafb1c2a67 100644 --- a/modules/@angular/common/test/pipes/i18n_plural_pipe_spec.ts +++ b/modules/@angular/common/test/pipes/i18n_plural_pipe_spec.ts @@ -4,7 +4,7 @@ import {afterEach, beforeEach, ddescribe, describe, expect, iit, it, xit} from ' export function main() { describe('I18nPluralPipe', () => { - var pipe: any /** TODO #9100 */; + var pipe: I18nPluralPipe; var mapping = {'=0': 'No messages.', '=1': 'One message.', 'other': 'There are some messages.'}; var interpolatedMapping = { '=0': 'No messages.', @@ -39,13 +39,12 @@ export function main() { }); it('should use \'other\' if value is undefined', () => { - var messageLength: any /** TODO #9100 */; - var val = pipe.transform(messageLength, interpolatedMapping); + var val = pipe.transform(void(0), interpolatedMapping); expect(val).toEqual('There are messages, that is .'); }); it('should not support bad arguments', - () => { expect(() => pipe.transform(0, 'hey')).toThrowError(); }); + () => { expect(() => pipe.transform(0, 'hey')).toThrowError(); }); }); }); diff --git a/modules/@angular/common/test/pipes/i18n_select_pipe_spec.ts b/modules/@angular/common/test/pipes/i18n_select_pipe_spec.ts index 3617392134..19fa51defb 100644 --- a/modules/@angular/common/test/pipes/i18n_select_pipe_spec.ts +++ b/modules/@angular/common/test/pipes/i18n_select_pipe_spec.ts @@ -4,7 +4,7 @@ import {afterEach, beforeEach, ddescribe, describe, expect, iit, it, xit} from ' export function main() { describe('I18nSelectPipe', () => { - var pipe: any /** TODO #9100 */; + var pipe: I18nSelectPipe; var mapping = {'male': 'Invite him.', 'female': 'Invite her.', 'other': 'Invite them.'}; beforeEach(() => { pipe = new I18nSelectPipe(); }); @@ -29,13 +29,12 @@ export function main() { }); it('should use \'other\' if value is undefined', () => { - var gender: any /** TODO #9100 */; - var val = pipe.transform(gender, mapping); + var val = pipe.transform(void(0), mapping); expect(val).toEqual('Invite them.'); }); it('should not support bad arguments', - () => { expect(() => pipe.transform('male', 'hey')).toThrowError(); }); + () => { expect(() => pipe.transform('male', 'hey')).toThrowError(); }); }); }); diff --git a/modules/@angular/common/test/pipes/json_pipe_spec.ts b/modules/@angular/common/test/pipes/json_pipe_spec.ts index 38f3679f6f..ecb2bf8489 100644 --- a/modules/@angular/common/test/pipes/json_pipe_spec.ts +++ b/modules/@angular/common/test/pipes/json_pipe_spec.ts @@ -1,7 +1,7 @@ import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach, inject,} from '@angular/core/testing/testing_internal'; import {AsyncTestCompleter} from '@angular/core/testing/testing_internal'; -import {TestComponentBuilder, ComponentFixture} from '@angular/compiler/testing'; -import {Json, RegExp, NumberWrapper, StringWrapper} from '../../src/facade/lang'; +import {TestComponentBuilder} from '@angular/compiler/testing'; +import {Json, StringWrapper} from '../../src/facade/lang'; import {Component} from '@angular/core'; import {JsonPipe} from '@angular/common'; @@ -9,9 +9,9 @@ import {JsonPipe} from '@angular/common'; export function main() { describe('JsonPipe', () => { var regNewLine = '\n'; - var inceptionObj: any /** TODO #9100 */; - var inceptionObjString: any /** TODO #9100 */; - var pipe: any /** TODO #9100 */; + var inceptionObj: any; + var inceptionObjString: string; + var pipe: JsonPipe; function normalize(obj: string): string { return StringWrapper.replace(obj, regNewLine, ''); } diff --git a/modules/@angular/common/test/pipes/lowercase_pipe_spec.ts b/modules/@angular/common/test/pipes/lowercase_pipe_spec.ts index 2dba2ba08e..6652e7e4f0 100644 --- a/modules/@angular/common/test/pipes/lowercase_pipe_spec.ts +++ b/modules/@angular/common/test/pipes/lowercase_pipe_spec.ts @@ -3,9 +3,9 @@ import {afterEach, beforeEach, ddescribe, describe, expect, iit, it, xit} from ' export function main() { describe('LowerCasePipe', () => { - var upper: any /** TODO #9100 */; - var lower: any /** TODO #9100 */; - var pipe: any /** TODO #9100 */; + var upper: string; + var lower: string; + var pipe: LowerCasePipe; beforeEach(() => { lower = 'something'; @@ -27,7 +27,7 @@ export function main() { }); it('should not support other objects', - () => { expect(() => pipe.transform(new Object())).toThrowError(); }); + () => { expect(() => pipe.transform({})).toThrowError(); }); }); }); diff --git a/modules/@angular/common/test/pipes/number_pipe_spec.ts b/modules/@angular/common/test/pipes/number_pipe_spec.ts index 5372114650..f50960bbc0 100644 --- a/modules/@angular/common/test/pipes/number_pipe_spec.ts +++ b/modules/@angular/common/test/pipes/number_pipe_spec.ts @@ -9,7 +9,7 @@ export function main() { // https://github.com/angular/angular/issues/3333 if (browserDetection.supportsIntlApi) { describe('DecimalPipe', () => { - var pipe: any /** TODO #9100 */; + var pipe: DecimalPipe; beforeEach(() => { pipe = new DecimalPipe(); }); @@ -30,7 +30,7 @@ export function main() { }); describe('PercentPipe', () => { - var pipe: any /** TODO #9100 */; + var pipe: PercentPipe; beforeEach(() => { pipe = new PercentPipe(); }); @@ -46,7 +46,7 @@ export function main() { }); describe('CurrencyPipe', () => { - var pipe: any /** TODO #9100 */; + var pipe: CurrencyPipe; beforeEach(() => { pipe = new CurrencyPipe(); }); diff --git a/modules/@angular/common/test/pipes/replace_pipe_spec.ts b/modules/@angular/common/test/pipes/replace_pipe_spec.ts index e6085e4618..53f0bf5432 100644 --- a/modules/@angular/common/test/pipes/replace_pipe_spec.ts +++ b/modules/@angular/common/test/pipes/replace_pipe_spec.ts @@ -7,8 +7,8 @@ import {RegExpWrapper, StringJoiner} from '../../src/facade/lang'; export function main() { describe('ReplacePipe', () => { var someNumber: number; - var str: any /** TODO #9100 */; - var pipe: any /** TODO #9100 */; + var str: string; + var pipe: ReplacePipe; beforeEach(() => { someNumber = 42; @@ -24,15 +24,15 @@ export function main() { }); it('should not support patterns other than strings and regular expressions', () => { - expect(() => pipe.transform(str, {}, 'Hugh')).toThrow(); - expect(() => pipe.transform(str, null, 'Hugh')).toThrow(); - expect(() => pipe.transform(str, 123, 'Hugh')).toThrow(); + expect(() => pipe.transform(str, {}, 'Hugh')).toThrow(); + expect(() => pipe.transform(str, null, 'Hugh')).toThrow(); + expect(() => pipe.transform(str, 123, 'Hugh')).toThrow(); }); it('should not support replacements other than strings and functions', () => { - expect(() => pipe.transform(str, 'Douglas', {})).toThrow(); - expect(() => pipe.transform(str, 'Douglas', null)).toThrow(); - expect(() => pipe.transform(str, 'Douglas', 123)).toThrow(); + expect(() => pipe.transform(str, 'Douglas', {})).toThrow(); + expect(() => pipe.transform(str, 'Douglas', null)).toThrow(); + expect(() => pipe.transform(str, 'Douglas', 123)).toThrow(); }); it('should return a new string with the pattern replaced', () => { @@ -42,7 +42,7 @@ export function main() { var result3 = pipe.transform(str, RegExpWrapper.create('a', 'i'), '_'); - var f = ((x: any /** TODO #9100 */) => { return 'Adams!'; }); + var f = ((x: any) => { return 'Adams!'; }); var result4 = pipe.transform(str, 'Adams', f); diff --git a/modules/@angular/common/test/pipes/slice_pipe_spec.ts b/modules/@angular/common/test/pipes/slice_pipe_spec.ts index aada4fbc73..977c2fed9a 100644 --- a/modules/@angular/common/test/pipes/slice_pipe_spec.ts +++ b/modules/@angular/common/test/pipes/slice_pipe_spec.ts @@ -10,8 +10,8 @@ import {SlicePipe} from '@angular/common'; export function main() { describe('SlicePipe', () => { var list: number[]; - var str: any /** TODO #9100 */; - var pipe: any /** TODO #9100 */; + var str: string; + var pipe: SlicePipe; beforeEach(() => { list = [1, 2, 3, 4, 5]; @@ -20,20 +20,17 @@ export function main() { }); describe('supports', () => { - it('should support strings', () => { expect(pipe.supports(str)).toBe(true); }); - it('should support lists', () => { expect(pipe.supports(list)).toBe(true); }); + it('should support strings', () => { expect(() => pipe.transform(str, 0)).not.toThrow(); }); + it('should support lists', () => { expect(() => pipe.transform(list, 0)).not.toThrow(); }); - it('should not support other objects', () => { - expect(pipe.supports(new Object())).toBe(false); - expect(pipe.supports(null)).toBe(false); - }); + it('should not support other objects', + () => { expect(() => pipe.transform({}, 0)).toThrow(); }); }); describe('transform', () => { - it('should return null if the value is null', () => { - expect(pipe.transform(null, [4, 2])).toBe(null); - }); + it('should return null if the value is null', + () => { expect(pipe.transform(null, 1)).toBe(null); }); it('should return all items after START index when START is positive and END is omitted', () => { diff --git a/modules/@angular/common/test/pipes/uppercase_pipe_spec.ts b/modules/@angular/common/test/pipes/uppercase_pipe_spec.ts index be5827abf1..a3eee1906b 100644 --- a/modules/@angular/common/test/pipes/uppercase_pipe_spec.ts +++ b/modules/@angular/common/test/pipes/uppercase_pipe_spec.ts @@ -3,9 +3,9 @@ import {afterEach, beforeEach, ddescribe, describe, expect, iit, it, xit} from ' export function main() { describe('UpperCasePipe', () => { - var upper: any /** TODO #9100 */; - var lower: any /** TODO #9100 */; - var pipe: any /** TODO #9100 */; + var upper: string; + var lower: string; + var pipe: UpperCasePipe; beforeEach(() => { lower = 'something'; @@ -28,7 +28,7 @@ export function main() { }); it('should not support other objects', - () => { expect(() => pipe.transform(new Object())).toThrowError(); }); + () => { expect(() => pipe.transform({})).toThrowError(); }); }); }); diff --git a/modules/@angular/facade/src/browser.ts b/modules/@angular/facade/src/browser.ts index ca8277f540..1222bfd094 100644 --- a/modules/@angular/facade/src/browser.ts +++ b/modules/@angular/facade/src/browser.ts @@ -6,7 +6,7 @@ var win = typeof window !== 'undefined' && window || {}; export {win as window}; export var document = win.document; export var location = win.location; -export var gc = win['gc'] ? () => win['gc']() : (): any /** TODO #9100 */ => null; +export var gc = win['gc'] ? () => win['gc']() : (): any => null; export var performance = win['performance'] ? win['performance'] : null; export const Event = win['Event']; export const MouseEvent = win['MouseEvent']; diff --git a/modules/@angular/facade/src/intl.ts b/modules/@angular/facade/src/intl.ts index 1a92f134e7..7b682e552d 100644 --- a/modules/@angular/facade/src/intl.ts +++ b/modules/@angular/facade/src/intl.ts @@ -127,13 +127,13 @@ function hour12Modify( } function digitCondition(prop: string, len: number): Intl.DateTimeFormatOptions { - var result = {}; - (result as any /** TODO #9100 */)[prop] = len == 2 ? '2-digit' : 'numeric'; + var result: {[k: string]: string} = {}; + result[prop] = len == 2 ? '2-digit' : 'numeric'; return result; } function nameCondition(prop: string, len: number): Intl.DateTimeFormatOptions { - var result = {}; - (result as any /** TODO #9100 */)[prop] = len < 4 ? 'short' : 'long'; + var result: {[k: string]: string} = {}; + result[prop] = len < 4 ? 'short' : 'long'; return result; }