refactor: add types (#9606)

relates to #9100
This commit is contained in:
Victor Berchet 2016-06-28 11:35:59 -07:00 committed by GitHub
parent 1620426393
commit 5ee84fe0f6
13 changed files with 68 additions and 70 deletions

View File

@ -36,7 +36,7 @@ export abstract class CompileMetadataWithType extends CompileMetadataWithIdentif
} }
export function metadataFromJson(data: {[key: string]: any}): any { export function metadataFromJson(data: {[key: string]: any}): any {
return (_COMPILE_METADATA_FROM_JSON as any /** TODO #9100 */)[data['class']](data); return (_COMPILE_METADATA_FROM_JSON as any)[data['class']](data);
} }
export class CompileAnimationEntryMetadata { export class CompileAnimationEntryMetadata {
@ -487,7 +487,7 @@ export class CompileTokenMap<VALUE> {
get(token: CompileTokenMetadata): VALUE { get(token: CompileTokenMetadata): VALUE {
var rk = token.runtimeCacheKey; var rk = token.runtimeCacheKey;
var ak = token.assetCacheKey; var ak = token.assetCacheKey;
var result: any /** TODO #9100 */; var result: VALUE;
if (isPresent(rk)) { if (isPresent(rk)) {
result = this._valueMap.get(rk); result = this._valueMap.get(rk);
} }

View File

@ -67,9 +67,9 @@ export abstract class RenderTypes {
export class DefaultRenderTypes implements RenderTypes { export class DefaultRenderTypes implements RenderTypes {
renderer = Identifiers.Renderer; renderer = Identifiers.Renderer;
renderText: any /** TODO #9100 */ = null; renderText: any = null;
renderElement: any /** TODO #9100 */ = null; renderElement: any = null;
renderComment: any /** TODO #9100 */ = null; renderComment: any = null;
renderNode: any /** TODO #9100 */ = null; renderNode: any = null;
renderEvent: any /** TODO #9100 */ = null; renderEvent: any = null;
} }

View File

@ -89,7 +89,7 @@ export class CssScannerError extends BaseException {
public rawMessage: string; public rawMessage: string;
public message: string; public message: string;
constructor(public token: CssToken, message: any /** TODO #9100 */) { constructor(public token: CssToken, message: string) {
super('Css Parse Error: ' + message); super('Css Parse Error: ' + message);
this.rawMessage = message; this.rawMessage = message;
} }
@ -208,7 +208,7 @@ export class CssScanner {
next = new CssToken(0, 0, 0, CssTokenType.EOF, 'end of file'); next = new CssToken(0, 0, 0, CssTokenType.EOF, 'end of file');
} }
var isMatchingType: any /** TODO #9100 */; var isMatchingType: boolean;
if (type == CssTokenType.IdentifierOrNumber) { if (type == CssTokenType.IdentifierOrNumber) {
// TODO (matsko): implement array traversal for lookup here // TODO (matsko): implement array traversal for lookup here
isMatchingType = next.type == CssTokenType.Number || next.type == CssTokenType.Identifier; isMatchingType = next.type == CssTokenType.Number || next.type == CssTokenType.Identifier;
@ -220,7 +220,7 @@ export class CssScanner {
// mode so that the parser can recover... // mode so that the parser can recover...
this.setMode(mode); this.setMode(mode);
var error: any /** TODO #9100 */ = null; var error: CssScannerError = null;
if (!isMatchingType || (isPresent(value) && value != next.strValue)) { if (!isMatchingType || (isPresent(value) && value != next.strValue)) {
var errorMessage = resolveEnumToken(CssTokenType, next.type) + ' does not match expected ' + var errorMessage = resolveEnumToken(CssTokenType, next.type) + ' does not match expected ' +
resolveEnumToken(CssTokenType, type) + ' value'; resolveEnumToken(CssTokenType, type) + ' value';

View File

@ -194,7 +194,7 @@ export class CssParser {
/** @internal */ /** @internal */
_parseStyleSheet(delimiters: number): CssStyleSheetAst { _parseStyleSheet(delimiters: number): CssStyleSheetAst {
const start = this._getScannerIndex(); const start = this._getScannerIndex();
var results: any[] /** TODO #9100 */ = []; var results: CssAst[] = [];
this._scanner.consumeEmptyStatements(); this._scanner.consumeEmptyStatements();
while (this._scanner.peek != chars.$EOF) { while (this._scanner.peek != chars.$EOF) {
this._scanner.setMode(CssLexerMode.BLOCK); this._scanner.setMode(CssLexerMode.BLOCK);
@ -325,7 +325,7 @@ export class CssParser {
_parseSelectors(delimiters: number): CssSelectorAst[] { _parseSelectors(delimiters: number): CssSelectorAst[] {
delimiters |= LBRACE_DELIM_FLAG | SEMICOLON_DELIM_FLAG; delimiters |= LBRACE_DELIM_FLAG | SEMICOLON_DELIM_FLAG;
var selectors: any[] /** TODO #9100 */ = []; var selectors: CssSelectorAst[] = [];
var isParsingSelectors = true; var isParsingSelectors = true;
while (isParsingSelectors) { while (isParsingSelectors) {
selectors.push(this._parseSelector(delimiters)); selectors.push(this._parseSelector(delimiters));
@ -378,7 +378,7 @@ export class CssParser {
this._consume(CssTokenType.Character, '{'); this._consume(CssTokenType.Character, '{');
var definitions: any[] /** TODO #9100 */ = []; var definitions: CssKeyframeDefinitionAst[] = [];
while (!characterContainsDelimiter(this._scanner.peek, delimiters)) { while (!characterContainsDelimiter(this._scanner.peek, delimiters)) {
definitions.push(this._parseKeyframeDefinition(delimiters)); definitions.push(this._parseKeyframeDefinition(delimiters));
} }
@ -392,7 +392,7 @@ export class CssParser {
/** @internal */ /** @internal */
_parseKeyframeDefinition(delimiters: number): CssKeyframeDefinitionAst { _parseKeyframeDefinition(delimiters: number): CssKeyframeDefinitionAst {
const start = this._getScannerIndex(); const start = this._getScannerIndex();
var stepTokens: any[] /** TODO #9100 */ = []; var stepTokens: CssToken[] = [];
delimiters |= LBRACE_DELIM_FLAG; delimiters |= LBRACE_DELIM_FLAG;
while (!characterContainsDelimiter(this._scanner.peek, delimiters)) { while (!characterContainsDelimiter(this._scanner.peek, delimiters)) {
stepTokens.push(this._parseKeyframeLabel(delimiters | COMMA_DELIM_FLAG)); stepTokens.push(this._parseKeyframeLabel(delimiters | COMMA_DELIM_FLAG));
@ -701,7 +701,7 @@ export class CssParser {
/** @internal */ /** @internal */
_collectUntilDelim(delimiters: number, assertType: CssTokenType = null): CssToken[] { _collectUntilDelim(delimiters: number, assertType: CssTokenType = null): CssToken[] {
var tokens: any[] /** TODO #9100 */ = []; var tokens: CssToken[] = [];
while (!characterContainsDelimiter(this._scanner.peek, delimiters)) { while (!characterContainsDelimiter(this._scanner.peek, delimiters)) {
var val = isPresent(assertType) ? this._consume(assertType) : this._scan(); var val = isPresent(assertType) ? this._consume(assertType) : this._scan();
tokens.push(val); tokens.push(val);
@ -720,7 +720,7 @@ export class CssParser {
this._consume(CssTokenType.Character, '{'); this._consume(CssTokenType.Character, '{');
this._scanner.consumeEmptyStatements(); this._scanner.consumeEmptyStatements();
var results: any[] /** TODO #9100 */ = []; var results: CssAst[] = [];
while (!characterContainsDelimiter(this._scanner.peek, delimiters)) { while (!characterContainsDelimiter(this._scanner.peek, delimiters)) {
results.push(this._parseRule(delimiters)); results.push(this._parseRule(delimiters));
} }
@ -770,7 +770,7 @@ export class CssParser {
this._scanner.setMode(CssLexerMode.STYLE_BLOCK); this._scanner.setMode(CssLexerMode.STYLE_BLOCK);
var prop = this._consume(CssTokenType.Identifier); var prop = this._consume(CssTokenType.Identifier);
var parseValue: any /** TODO #9100 */, value: any /** TODO #9100 */ = null; var parseValue: boolean, value: CssStyleValueAst = null;
// the colon value separates the prop from the style. // the colon value separates the prop from the style.
// there are a few cases as to what could happen if it // there are a few cases as to what could happen if it

View File

@ -34,7 +34,7 @@ const LIFECYCLE_PROPS: Map<any, string> = MapWrapper.createFromPairs([
[LifecycleHooks.AfterViewChecked, 'ngAfterViewChecked'], [LifecycleHooks.AfterViewChecked, 'ngAfterViewChecked'],
]); ]);
export function hasLifecycleHook(hook: LifecycleHooks, token: any /** TODO #9100 */): boolean { export function hasLifecycleHook(hook: LifecycleHooks, token: any): boolean {
var lcInterface = LIFECYCLE_INTERFACES.get(hook); var lcInterface = LIFECYCLE_INTERFACES.get(hook);
var lcProp = LIFECYCLE_PROPS.get(hook); var lcProp = LIFECYCLE_PROPS.get(hook);
return reflector.hasLifecycleHook(token, lcInterface, lcProp); return reflector.hasLifecycleHook(token, lcInterface, lcProp);

View File

@ -97,7 +97,7 @@ export class DirectiveResolver {
queries: {[key: string]: any}, directiveType: Type): DirectiveMetadata { queries: {[key: string]: any}, directiveType: Type): DirectiveMetadata {
var mergedInputs = isPresent(dm.inputs) ? ListWrapper.concat(dm.inputs, inputs) : inputs; var mergedInputs = isPresent(dm.inputs) ? ListWrapper.concat(dm.inputs, inputs) : inputs;
var mergedOutputs: any /** TODO #9100 */; var mergedOutputs: string[];
if (isPresent(dm.outputs)) { if (isPresent(dm.outputs)) {
dm.outputs.forEach((propName: string) => { dm.outputs.forEach((propName: string) => {
if (ListWrapper.contains(outputs, propName)) { if (ListWrapper.contains(outputs, propName)) {

View File

@ -346,8 +346,8 @@ export class ApplicationRef_ extends ApplicationRef {
zone.run(() => { this._exceptionHandler = _injector.get(ExceptionHandler); }); zone.run(() => { this._exceptionHandler = _injector.get(ExceptionHandler); });
this._asyncInitDonePromise = this.run(() => { this._asyncInitDonePromise = this.run(() => {
let inits: Function[] = _injector.get(APP_INITIALIZER, null); let inits: Function[] = _injector.get(APP_INITIALIZER, null);
var asyncInitResults: any[] /** TODO #9100 */ = []; var asyncInitResults: Promise<any>[] = [];
var asyncInitDonePromise: any /** TODO #9100 */; var asyncInitDonePromise: Promise<any>;
if (isPresent(inits)) { if (isPresent(inits)) {
for (var i = 0; i < inits.length; i++) { for (var i = 0; i < inits.length; i++) {
var initResult = inits[i](); var initResult = inits[i]();
@ -391,7 +391,7 @@ export class ApplicationRef_ extends ApplicationRef {
run(callback: Function): any { run(callback: Function): any {
var zone = this.injector.get(NgZone); var zone = this.injector.get(NgZone);
var result: any /** TODO #9100 */; var result: any;
// Note: Don't use zone.runGuarded as we want to know about // Note: Don't use zone.runGuarded as we want to know about
// the thrown exception! // the thrown exception!
// Note: the completer needs to be created outside // Note: the completer needs to be created outside

View File

@ -51,7 +51,7 @@ import {stringify} from '../facade/lang';
* @stable * @stable
*/ */
export class InjectMetadata { export class InjectMetadata {
constructor(public token: any /** TODO #9100 */) {} constructor(public token: any) {}
toString(): string { return `@Inject(${stringify(this.token)})`; } toString(): string { return `@Inject(${stringify(this.token)})`; }
} }
@ -89,7 +89,7 @@ export class OptionalMetadata {
* @stable * @stable
*/ */
export class DependencyMetadata { export class DependencyMetadata {
get token(): any /** TODO #9100 */ { return null; } get token(): any { return null; }
} }
/** /**

View File

@ -31,7 +31,7 @@ export class Provider {
/** /**
* Token used when retrieving this provider. Usually, it is a type {@link Type}. * Token used when retrieving this provider. Usually, it is a type {@link Type}.
*/ */
token: any /** TODO #9100 */; token: any;
/** /**
* Binds a DI token to an implementation class. * Binds a DI token to an implementation class.
@ -77,7 +77,7 @@ export class Provider {
* expect(injector.get("message")).toEqual('Hello'); * expect(injector.get("message")).toEqual('Hello');
* ``` * ```
*/ */
useValue: any /** TODO #9100 */; useValue: any;
/** /**
* Binds a DI token to an existing token. * Binds a DI token to an existing token.
@ -111,7 +111,7 @@ export class Provider {
* expect(injectorClass.get(Vehicle) instanceof Car).toBe(true); * expect(injectorClass.get(Vehicle) instanceof Car).toBe(true);
* ``` * ```
*/ */
useExisting: any /** TODO #9100 */; useExisting: any;
/** /**
* Binds a DI token to a function which computes the value. * Binds a DI token to a function which computes the value.
@ -157,8 +157,7 @@ export class Provider {
/** @internal */ /** @internal */
_multi: boolean; _multi: boolean;
constructor( constructor(token: any, {useClass, useValue, useExisting, useFactory, deps, multi}: {
token: any /** TODO #9100 */, {useClass, useValue, useExisting, useFactory, deps, multi}: {
useClass?: Type, useClass?: Type,
useValue?: any, useValue?: any,
useExisting?: any, useExisting?: any,
@ -215,7 +214,7 @@ export class Provider {
* @ts2dart_const * @ts2dart_const
*/ */
export class Binding extends Provider { export class Binding extends Provider {
constructor(token: any /** TODO #9100 */, {toClass, toValue, toAlias, toFactory, deps, multi}: { constructor(token: any, {toClass, toValue, toAlias, toFactory, deps, multi}: {
toClass?: Type, toClass?: Type,
toValue?: any, toValue?: any,
toAlias?: any, toAlias?: any,
@ -264,7 +263,7 @@ export class Binding extends Provider {
* *
* @deprecated * @deprecated
*/ */
export function bind(token: any /** TODO #9100 */): ProviderBuilder { export function bind(token: any): ProviderBuilder {
return new ProviderBuilder(token); return new ProviderBuilder(token);
} }
@ -273,7 +272,7 @@ export function bind(token: any /** TODO #9100 */): ProviderBuilder {
* @deprecated * @deprecated
*/ */
export class ProviderBuilder { export class ProviderBuilder {
constructor(public token: any /** TODO #9100 */) {} constructor(public token: any) {}
/** /**
* Binds a DI token to a class. * Binds a DI token to a class.
@ -398,8 +397,7 @@ export class ProviderBuilder {
* <!-- TODO: improve the docs --> * <!-- TODO: improve the docs -->
* @deprecated * @deprecated
*/ */
export function provide( export function provide(token: any, {useClass, useValue, useExisting, useFactory, deps, multi}: {
token: any /** TODO #9100 */, {useClass, useValue, useExisting, useFactory, deps, multi}: {
useClass?: Type, useClass?: Type,
useValue?: any, useValue?: any,
useExisting?: any, useExisting?: any,

View File

@ -8,20 +8,20 @@
import {ListWrapper} from '../facade/collection'; import {ListWrapper} from '../facade/collection';
import {BaseException, WrappedException} from '../facade/exceptions'; import {BaseException, WrappedException} from '../facade/exceptions';
import {isBlank, stringify} from '../facade/lang'; import {Type, isBlank, stringify} from '../facade/lang';
import {Provider} from './provider';
import {ReflectiveInjector} from './reflective_injector'; import {ReflectiveInjector} from './reflective_injector';
import {ReflectiveKey} from './reflective_key'; import {ReflectiveKey} from './reflective_key';
function findFirstClosedCycle(keys: any[]): any[] { function findFirstClosedCycle(keys: any[]): any[] {
var res: any[] /** TODO #9100 */ = []; var res: any[] = [];
for (var i = 0; i < keys.length; ++i) { for (var i = 0; i < keys.length; ++i) {
if (ListWrapper.contains(res, keys[i])) { if (ListWrapper.contains(res, keys[i])) {
res.push(keys[i]); res.push(keys[i]);
return res; return res;
} else {
res.push(keys[i]);
} }
res.push(keys[i]);
} }
return res; return res;
} }
@ -31,9 +31,9 @@ function constructResolvingPath(keys: any[]): string {
var reversed = findFirstClosedCycle(ListWrapper.reversed(keys)); var reversed = findFirstClosedCycle(ListWrapper.reversed(keys));
var tokenStrs = reversed.map(k => stringify(k.token)); var tokenStrs = reversed.map(k => stringify(k.token));
return ' (' + tokenStrs.join(' -> ') + ')'; return ' (' + tokenStrs.join(' -> ') + ')';
} else {
return '';
} }
return '';
} }
@ -156,8 +156,8 @@ export class InstantiationError extends WrappedException {
injectors: ReflectiveInjector[]; injectors: ReflectiveInjector[];
constructor( constructor(
injector: ReflectiveInjector, originalException: any /** TODO #9100 */, injector: ReflectiveInjector, originalException: any, originalStack: any,
originalStack: any /** TODO #9100 */, key: ReflectiveKey) { key: ReflectiveKey) {
super('DI Exception', originalException, originalStack, null); super('DI Exception', originalException, originalStack, null);
this.keys = [key]; this.keys = [key];
this.injectors = [injector]; this.injectors = [injector];
@ -190,7 +190,7 @@ export class InstantiationError extends WrappedException {
* @stable * @stable
*/ */
export class InvalidProviderError extends BaseException { export class InvalidProviderError extends BaseException {
constructor(provider: any /** TODO #9100 */) { constructor(provider: any) {
super(`Invalid provider - only instances of Provider and Type are allowed, got: ${provider}`); super(`Invalid provider - only instances of Provider and Type are allowed, got: ${provider}`);
} }
} }
@ -225,12 +225,12 @@ export class InvalidProviderError extends BaseException {
* @stable * @stable
*/ */
export class NoAnnotationError extends BaseException { export class NoAnnotationError extends BaseException {
constructor(typeOrFunc: any /** TODO #9100 */, params: any[][]) { constructor(typeOrFunc: Type|Function, params: any[][]) {
super(NoAnnotationError._genMessage(typeOrFunc, params)); super(NoAnnotationError._genMessage(typeOrFunc, params));
} }
private static _genMessage(typeOrFunc: any /** TODO #9100 */, params: any[][]) { private static _genMessage(typeOrFunc: Type|Function, params: any[][]) {
var signature: any[] /** TODO #9100 */ = []; var signature: string[] = [];
for (var i = 0, ii = params.length; i < ii; i++) { for (var i = 0, ii = params.length; i < ii; i++) {
var parameter = params[i]; var parameter = params[i];
if (isBlank(parameter) || parameter.length == 0) { if (isBlank(parameter) || parameter.length == 0) {
@ -261,7 +261,7 @@ export class NoAnnotationError extends BaseException {
* @stable * @stable
*/ */
export class OutOfBoundsError extends BaseException { export class OutOfBoundsError extends BaseException {
constructor(index: any /** TODO #9100 */) { super(`Index ${index} is out-of-bounds.`); } constructor(index: number) { super(`Index ${index} is out-of-bounds.`); }
} }
// TODO: add a working example after alpha38 is released // TODO: add a working example after alpha38 is released
@ -278,7 +278,7 @@ export class OutOfBoundsError extends BaseException {
* ``` * ```
*/ */
export class MixingMultiProvidersWithRegularProvidersError extends BaseException { export class MixingMultiProvidersWithRegularProvidersError extends BaseException {
constructor(provider1: any /** TODO #9100 */, provider2: any /** TODO #9100 */) { constructor(provider1: any, provider2: any) {
super( super(
'Cannot mix multi providers and regular providers, got: ' + provider1.toString() + ' ' + 'Cannot mix multi providers and regular providers, got: ' + provider1.toString() + ' ' +
provider2.toString()); provider2.toString());

View File

@ -739,7 +739,7 @@ export class ReflectiveInjector_ implements ReflectiveInjector {
throw e; throw e;
} }
var obj: any /** TODO #9100 */; var obj: any;
try { try {
switch (length) { switch (length) {
case 0: case 0:
@ -892,9 +892,9 @@ export class ReflectiveInjector_ implements ReflectiveInjector {
var INJECTOR_KEY = ReflectiveKey.get(Injector); var INJECTOR_KEY = ReflectiveKey.get(Injector);
function _mapProviders(injector: ReflectiveInjector_, fn: Function): any[] { function _mapProviders(injector: ReflectiveInjector_, fn: Function): any[] {
var res: any[] /** TODO #9100 */ = []; var res: any[] = new Array(injector._proto.numberOfProviders);
for (var i = 0; i < injector._proto.numberOfProviders; ++i) { for (var i = 0; i < injector._proto.numberOfProviders; ++i) {
res.push(fn(injector._proto.getProviderAtIndex(i))); res[i] = fn(injector._proto.getProviderAtIndex(i));
} }
return res; return res;
} }

View File

@ -30,7 +30,7 @@ export class ReflectiveDependency {
} }
} }
const _EMPTY_LIST: any[] /** TODO #9100 */ = /*@ts2dart_const*/[]; const _EMPTY_LIST: any[] = /*@ts2dart_const*/[];
/** /**
* An internal resolved representation of a {@link Provider} used by the {@link Injector}. * An internal resolved representation of a {@link Provider} used by the {@link Injector}.
@ -105,13 +105,13 @@ export class ResolvedReflectiveFactory {
*/ */
export function resolveReflectiveFactory(provider: Provider): ResolvedReflectiveFactory { export function resolveReflectiveFactory(provider: Provider): ResolvedReflectiveFactory {
var factoryFn: Function; var factoryFn: Function;
var resolvedDeps: any /** TODO #9100 */; var resolvedDeps: ReflectiveDependency[];
if (isPresent(provider.useClass)) { if (isPresent(provider.useClass)) {
var useClass = resolveForwardRef(provider.useClass); var useClass = resolveForwardRef(provider.useClass);
factoryFn = reflector.factory(useClass); factoryFn = reflector.factory(useClass);
resolvedDeps = _dependenciesFor(useClass); resolvedDeps = _dependenciesFor(useClass);
} else if (isPresent(provider.useExisting)) { } else if (isPresent(provider.useExisting)) {
factoryFn = (aliasInstance: any /** TODO #9100 */) => aliasInstance; factoryFn = (aliasInstance: any) => aliasInstance;
resolvedDeps = [ReflectiveDependency.fromKey(ReflectiveKey.get(provider.useExisting))]; resolvedDeps = [ReflectiveDependency.fromKey(ReflectiveKey.get(provider.useExisting))];
} else if (isPresent(provider.useFactory)) { } else if (isPresent(provider.useFactory)) {
factoryFn = provider.useFactory; factoryFn = provider.useFactory;
@ -169,7 +169,7 @@ export function mergeResolvedReflectiveProviders(
normalizedProvidersMap.set(provider.key.id, provider); normalizedProvidersMap.set(provider.key.id, provider);
} }
} else { } else {
var resolvedProvider: any /** TODO #9100 */; var resolvedProvider: ResolvedReflectiveProvider;
if (provider.multiProvider) { if (provider.multiProvider) {
resolvedProvider = new ResolvedReflectiveProvider_( resolvedProvider = new ResolvedReflectiveProvider_(
provider.key, ListWrapper.clone(provider.resolvedFactories), provider.multiProvider); provider.key, ListWrapper.clone(provider.resolvedFactories), provider.multiProvider);

View File

@ -115,7 +115,7 @@ function initializeGenericWorkerRenderer(injector: Injector) {
// initialize message services after the bus has been created // initialize message services after the bus has been created
let services = injector.get(WORKER_UI_STARTABLE_MESSAGING_SERVICE); let services = injector.get(WORKER_UI_STARTABLE_MESSAGING_SERVICE);
zone.runGuarded(() => { services.forEach((svc: any /** TODO #9100 */) => { svc.start(); }); }); zone.runGuarded(() => { services.forEach((svc: any) => { svc.start(); }); });
} }
function messageBusFactory(instance: WebWorkerInstance): MessageBus { function messageBusFactory(instance: WebWorkerInstance): MessageBus {