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';
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 */;

View File

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

View File

@ -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<any>;
var pipe: AsyncPipe;
var ref: any;
var message = {};
beforeEach(() => {
emitter = new EventEmitter();

View File

@ -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');

View File

@ -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, <any>'hey')).toThrowError(); });
});
});

View File

@ -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', <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 {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, ''); }

View File

@ -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(<any>{})).toThrowError(); });
});
});

View File

@ -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(); });

View File

@ -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, <any>{}, 'Hugh')).toThrow();
expect(() => pipe.transform(str, <any>null, 'Hugh')).toThrow();
expect(() => pipe.transform(str, <any>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', <any>{})).toThrow();
expect(() => pipe.transform(str, 'Douglas', <any>null)).toThrow();
expect(() => pipe.transform(str, 'Douglas', <any>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);

View File

@ -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',
() => {

View File

@ -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(<any>{})).toThrowError(); });
});
});

View File

@ -6,7 +6,7 @@ var win = typeof window !== 'undefined' && window || <any>{};
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'];

View File

@ -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;
}