refactor: add types (#9288)

This commit is contained in:
Victor Berchet 2016-06-17 10:57:32 -07:00 committed by GitHub
parent 8879aa1df4
commit 5e3ccbcea9
14 changed files with 66 additions and 72 deletions

View File

@ -4,8 +4,8 @@ import {afterEach, beforeEach, ddescribe, describe, expect, iit, it, xit} from '
import {PromiseWrapper} from '../../src/facade/promise'; import {PromiseWrapper} from '../../src/facade/promise';
export function main() { export function main() {
function syncValidator(_: any /** TODO #9100 */): any /** TODO #9100 */ { return null; } function syncValidator(_: any): any { return null; }
function asyncValidator(_: any /** TODO #9100 */) { return PromiseWrapper.resolve(null); } function asyncValidator(_: any) { return PromiseWrapper.resolve(null); }
describe('Form Builder', () => { describe('Form Builder', () => {
var b: any /** TODO #9100 */; var b: any /** TODO #9100 */;

View File

@ -561,7 +561,7 @@ export function main() {
</select> </select>
</div>`; </div>`;
var fixture: any /** TODO #9100 */; var fixture: ComponentFixture<MyComp8>;
tcb.overrideTemplate(MyComp8, t) tcb.overrideTemplate(MyComp8, t)
.createAsync(MyComp8) .createAsync(MyComp8)
.then((compFixture) => fixture = compFixture); .then((compFixture) => fixture = compFixture);
@ -952,7 +952,7 @@ export function main() {
<input type="text" ngControl="login"> <input type="text" ngControl="login">
</div>`; </div>`;
var fixture: any /** TODO #9100 */; var fixture: ComponentFixture<MyComp8>;
tcb.overrideTemplate(MyComp8, t).createAsync(MyComp8).then((root) => fixture = root); tcb.overrideTemplate(MyComp8, t).createAsync(MyComp8).then((root) => fixture = root);
tick(); tick();

View File

@ -13,10 +13,10 @@ export function main() {
describe('AsyncPipe', () => { describe('AsyncPipe', () => {
describe('Observable', () => { describe('Observable', () => {
var emitter: any /** TODO #9100 */; var emitter: EventEmitter<any>;
var pipe: any /** TODO #9100 */; var pipe: AsyncPipe;
var ref: any /** TODO #9100 */; var ref: any;
var message = new Object(); var message = {};
beforeEach(() => { beforeEach(() => {
emitter = new EventEmitter(); emitter = new EventEmitter();

View File

@ -7,8 +7,8 @@ import {DateWrapper} from '../../src/facade/lang';
export function main() { export function main() {
describe('DatePipe', () => { describe('DatePipe', () => {
var date: any /** TODO #9100 */; var date: Date;
var pipe: any /** TODO #9100 */; var pipe: DatePipe;
beforeEach(() => { beforeEach(() => {
date = DateWrapper.create(2015, 6, 15, 21, 43, 11); date = DateWrapper.create(2015, 6, 15, 21, 43, 11);
@ -18,22 +18,21 @@ export function main() {
it('should be marked as pure', it('should be marked as pure',
() => { expect(new PipeResolver().resolve(DatePipe).pure).toEqual(true); }); () => { 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 // TODO(mlaval): enable tests when Intl API is no longer used, see
// https://github.com/angular/angular/issues/3333 // https://github.com/angular/angular/issues/3333
if (browserDetection.supportsIntlApi) { 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', () => { describe('transform', () => {
it('should format each component correctly', () => { it('should format each component correctly', () => {
expect(pipe.transform(date, 'y')).toEqual('2015'); expect(pipe.transform(date, 'y')).toEqual('2015');

View File

@ -4,7 +4,7 @@ import {afterEach, beforeEach, ddescribe, describe, expect, iit, it, xit} from '
export function main() { export function main() {
describe('I18nPluralPipe', () => { describe('I18nPluralPipe', () => {
var pipe: any /** TODO #9100 */; var pipe: I18nPluralPipe;
var mapping = {'=0': 'No messages.', '=1': 'One message.', 'other': 'There are some messages.'}; var mapping = {'=0': 'No messages.', '=1': 'One message.', 'other': 'There are some messages.'};
var interpolatedMapping = { var interpolatedMapping = {
'=0': 'No messages.', '=0': 'No messages.',
@ -39,13 +39,12 @@ export function main() {
}); });
it('should use \'other\' if value is undefined', () => { it('should use \'other\' if value is undefined', () => {
var messageLength: any /** TODO #9100 */; var val = pipe.transform(void(0), interpolatedMapping);
var val = pipe.transform(messageLength, interpolatedMapping);
expect(val).toEqual('There are messages, that is .'); expect(val).toEqual('There are messages, that is .');
}); });
it('should not support bad arguments', it('should not support bad arguments',
() => { expect(() => pipe.transform(0, 'hey')).toThrowError(); }); () => { expect(() => pipe.transform(0, <any>'hey')).toThrowError(); });
}); });
}); });

View File

@ -4,7 +4,7 @@ import {afterEach, beforeEach, ddescribe, describe, expect, iit, it, xit} from '
export function main() { export function main() {
describe('I18nSelectPipe', () => { describe('I18nSelectPipe', () => {
var pipe: any /** TODO #9100 */; var pipe: I18nSelectPipe;
var mapping = {'male': 'Invite him.', 'female': 'Invite her.', 'other': 'Invite them.'}; var mapping = {'male': 'Invite him.', 'female': 'Invite her.', 'other': 'Invite them.'};
beforeEach(() => { pipe = new I18nSelectPipe(); }); beforeEach(() => { pipe = new I18nSelectPipe(); });
@ -29,13 +29,12 @@ export function main() {
}); });
it('should use \'other\' if value is undefined', () => { it('should use \'other\' if value is undefined', () => {
var gender: any /** TODO #9100 */; var val = pipe.transform(void(0), mapping);
var val = pipe.transform(gender, mapping);
expect(val).toEqual('Invite them.'); expect(val).toEqual('Invite them.');
}); });
it('should not support bad arguments', it('should not support bad arguments',
() => { expect(() => pipe.transform('male', 'hey')).toThrowError(); }); () => { expect(() => pipe.transform('male', <any>'hey')).toThrowError(); });
}); });
}); });

View File

@ -1,7 +1,7 @@
import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach, inject,} from '@angular/core/testing/testing_internal'; 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 {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
import {TestComponentBuilder, ComponentFixture} from '@angular/compiler/testing'; import {TestComponentBuilder} from '@angular/compiler/testing';
import {Json, RegExp, NumberWrapper, StringWrapper} from '../../src/facade/lang'; import {Json, StringWrapper} from '../../src/facade/lang';
import {Component} from '@angular/core'; import {Component} from '@angular/core';
import {JsonPipe} from '@angular/common'; import {JsonPipe} from '@angular/common';
@ -9,9 +9,9 @@ import {JsonPipe} from '@angular/common';
export function main() { export function main() {
describe('JsonPipe', () => { describe('JsonPipe', () => {
var regNewLine = '\n'; var regNewLine = '\n';
var inceptionObj: any /** TODO #9100 */; var inceptionObj: any;
var inceptionObjString: any /** TODO #9100 */; var inceptionObjString: string;
var pipe: any /** TODO #9100 */; var pipe: JsonPipe;
function normalize(obj: string): string { return StringWrapper.replace(obj, regNewLine, ''); } function normalize(obj: string): string { return StringWrapper.replace(obj, regNewLine, ''); }

View File

@ -3,9 +3,9 @@ import {afterEach, beforeEach, ddescribe, describe, expect, iit, it, xit} from '
export function main() { export function main() {
describe('LowerCasePipe', () => { describe('LowerCasePipe', () => {
var upper: any /** TODO #9100 */; var upper: string;
var lower: any /** TODO #9100 */; var lower: string;
var pipe: any /** TODO #9100 */; var pipe: LowerCasePipe;
beforeEach(() => { beforeEach(() => {
lower = 'something'; lower = 'something';
@ -27,7 +27,7 @@ export function main() {
}); });
it('should not support other objects', it('should not support other objects',
() => { expect(() => pipe.transform(new Object())).toThrowError(); }); () => { expect(() => pipe.transform(<any>{})).toThrowError(); });
}); });
}); });

View File

@ -9,7 +9,7 @@ export function main() {
// https://github.com/angular/angular/issues/3333 // https://github.com/angular/angular/issues/3333
if (browserDetection.supportsIntlApi) { if (browserDetection.supportsIntlApi) {
describe('DecimalPipe', () => { describe('DecimalPipe', () => {
var pipe: any /** TODO #9100 */; var pipe: DecimalPipe;
beforeEach(() => { pipe = new DecimalPipe(); }); beforeEach(() => { pipe = new DecimalPipe(); });
@ -30,7 +30,7 @@ export function main() {
}); });
describe('PercentPipe', () => { describe('PercentPipe', () => {
var pipe: any /** TODO #9100 */; var pipe: PercentPipe;
beforeEach(() => { pipe = new PercentPipe(); }); beforeEach(() => { pipe = new PercentPipe(); });
@ -46,7 +46,7 @@ export function main() {
}); });
describe('CurrencyPipe', () => { describe('CurrencyPipe', () => {
var pipe: any /** TODO #9100 */; var pipe: CurrencyPipe;
beforeEach(() => { pipe = new CurrencyPipe(); }); beforeEach(() => { pipe = new CurrencyPipe(); });

View File

@ -7,8 +7,8 @@ import {RegExpWrapper, StringJoiner} from '../../src/facade/lang';
export function main() { export function main() {
describe('ReplacePipe', () => { describe('ReplacePipe', () => {
var someNumber: number; var someNumber: number;
var str: any /** TODO #9100 */; var str: string;
var pipe: any /** TODO #9100 */; var pipe: ReplacePipe;
beforeEach(() => { beforeEach(() => {
someNumber = 42; someNumber = 42;
@ -24,15 +24,15 @@ export function main() {
}); });
it('should not support patterns other than strings and regular expressions', () => { it('should not support patterns other than strings and regular expressions', () => {
expect(() => pipe.transform(str, {}, 'Hugh')).toThrow(); expect(() => pipe.transform(str, <any>{}, 'Hugh')).toThrow();
expect(() => pipe.transform(str, null, 'Hugh')).toThrow(); expect(() => pipe.transform(str, <any>null, 'Hugh')).toThrow();
expect(() => pipe.transform(str, 123, 'Hugh')).toThrow(); expect(() => pipe.transform(str, <any>123, 'Hugh')).toThrow();
}); });
it('should not support replacements other than strings and functions', () => { it('should not support replacements other than strings and functions', () => {
expect(() => pipe.transform(str, 'Douglas', {})).toThrow(); expect(() => pipe.transform(str, 'Douglas', <any>{})).toThrow();
expect(() => pipe.transform(str, 'Douglas', null)).toThrow(); expect(() => pipe.transform(str, 'Douglas', <any>null)).toThrow();
expect(() => pipe.transform(str, 'Douglas', 123)).toThrow(); expect(() => pipe.transform(str, 'Douglas', <any>123)).toThrow();
}); });
it('should return a new string with the pattern replaced', () => { 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 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); var result4 = pipe.transform(str, 'Adams', f);

View File

@ -10,8 +10,8 @@ import {SlicePipe} from '@angular/common';
export function main() { export function main() {
describe('SlicePipe', () => { describe('SlicePipe', () => {
var list: number[]; var list: number[];
var str: any /** TODO #9100 */; var str: string;
var pipe: any /** TODO #9100 */; var pipe: SlicePipe;
beforeEach(() => { beforeEach(() => {
list = [1, 2, 3, 4, 5]; list = [1, 2, 3, 4, 5];
@ -20,20 +20,17 @@ export function main() {
}); });
describe('supports', () => { describe('supports', () => {
it('should support strings', () => { expect(pipe.supports(str)).toBe(true); }); it('should support strings', () => { expect(() => pipe.transform(str, 0)).not.toThrow(); });
it('should support lists', () => { expect(pipe.supports(list)).toBe(true); }); it('should support lists', () => { expect(() => pipe.transform(list, 0)).not.toThrow(); });
it('should not support other objects', () => { it('should not support other objects',
expect(pipe.supports(new Object())).toBe(false); () => { expect(() => pipe.transform({}, 0)).toThrow(); });
expect(pipe.supports(null)).toBe(false);
});
}); });
describe('transform', () => { describe('transform', () => {
it('should return null if the value is null', () => { it('should return null if the value is null',
expect(pipe.transform(null, [4, 2])).toBe(null); () => { expect(pipe.transform(null, 1)).toBe(null); });
});
it('should return all items after START index when START is positive and END is omitted', it('should return all items after START index when START is positive and END is omitted',
() => { () => {

View File

@ -3,9 +3,9 @@ import {afterEach, beforeEach, ddescribe, describe, expect, iit, it, xit} from '
export function main() { export function main() {
describe('UpperCasePipe', () => { describe('UpperCasePipe', () => {
var upper: any /** TODO #9100 */; var upper: string;
var lower: any /** TODO #9100 */; var lower: string;
var pipe: any /** TODO #9100 */; var pipe: UpperCasePipe;
beforeEach(() => { beforeEach(() => {
lower = 'something'; lower = 'something';
@ -28,7 +28,7 @@ export function main() {
}); });
it('should not support other objects', it('should not support other objects',
() => { expect(() => pipe.transform(new Object())).toThrowError(); }); () => { expect(() => pipe.transform(<any>{})).toThrowError(); });
}); });
}); });

View File

@ -6,7 +6,7 @@ var win = typeof window !== 'undefined' && window || <any>{};
export {win as window}; export {win as window};
export var document = win.document; export var document = win.document;
export var location = win.location; 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 var performance = win['performance'] ? win['performance'] : null;
export const Event = win['Event']; export const Event = win['Event'];
export const MouseEvent = win['MouseEvent']; export const MouseEvent = win['MouseEvent'];

View File

@ -127,13 +127,13 @@ function hour12Modify(
} }
function digitCondition(prop: string, len: number): Intl.DateTimeFormatOptions { function digitCondition(prop: string, len: number): Intl.DateTimeFormatOptions {
var result = {}; var result: {[k: string]: string} = {};
(result as any /** TODO #9100 */)[prop] = len == 2 ? '2-digit' : 'numeric'; result[prop] = len == 2 ? '2-digit' : 'numeric';
return result; return result;
} }
function nameCondition(prop: string, len: number): Intl.DateTimeFormatOptions { function nameCondition(prop: string, len: number): Intl.DateTimeFormatOptions {
var result = {}; var result: {[k: string]: string} = {};
(result as any /** TODO #9100 */)[prop] = len < 4 ? 'short' : 'long'; result[prop] = len < 4 ? 'short' : 'long';
return result; return result;
} }