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 {
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 {
@ -487,7 +487,7 @@ export class CompileTokenMap<VALUE> {
get(token: CompileTokenMetadata): VALUE {
var rk = token.runtimeCacheKey;
var ak = token.assetCacheKey;
var result: any /** TODO #9100 */;
var result: VALUE;
if (isPresent(rk)) {
result = this._valueMap.get(rk);
}

View File

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

View File

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

View File

@ -194,7 +194,7 @@ export class CssParser {
/** @internal */
_parseStyleSheet(delimiters: number): CssStyleSheetAst {
const start = this._getScannerIndex();
var results: any[] /** TODO #9100 */ = [];
var results: CssAst[] = [];
this._scanner.consumeEmptyStatements();
while (this._scanner.peek != chars.$EOF) {
this._scanner.setMode(CssLexerMode.BLOCK);
@ -325,7 +325,7 @@ export class CssParser {
_parseSelectors(delimiters: number): CssSelectorAst[] {
delimiters |= LBRACE_DELIM_FLAG | SEMICOLON_DELIM_FLAG;
var selectors: any[] /** TODO #9100 */ = [];
var selectors: CssSelectorAst[] = [];
var isParsingSelectors = true;
while (isParsingSelectors) {
selectors.push(this._parseSelector(delimiters));
@ -378,7 +378,7 @@ export class CssParser {
this._consume(CssTokenType.Character, '{');
var definitions: any[] /** TODO #9100 */ = [];
var definitions: CssKeyframeDefinitionAst[] = [];
while (!characterContainsDelimiter(this._scanner.peek, delimiters)) {
definitions.push(this._parseKeyframeDefinition(delimiters));
}
@ -392,7 +392,7 @@ export class CssParser {
/** @internal */
_parseKeyframeDefinition(delimiters: number): CssKeyframeDefinitionAst {
const start = this._getScannerIndex();
var stepTokens: any[] /** TODO #9100 */ = [];
var stepTokens: CssToken[] = [];
delimiters |= LBRACE_DELIM_FLAG;
while (!characterContainsDelimiter(this._scanner.peek, delimiters)) {
stepTokens.push(this._parseKeyframeLabel(delimiters | COMMA_DELIM_FLAG));
@ -701,7 +701,7 @@ export class CssParser {
/** @internal */
_collectUntilDelim(delimiters: number, assertType: CssTokenType = null): CssToken[] {
var tokens: any[] /** TODO #9100 */ = [];
var tokens: CssToken[] = [];
while (!characterContainsDelimiter(this._scanner.peek, delimiters)) {
var val = isPresent(assertType) ? this._consume(assertType) : this._scan();
tokens.push(val);
@ -720,7 +720,7 @@ export class CssParser {
this._consume(CssTokenType.Character, '{');
this._scanner.consumeEmptyStatements();
var results: any[] /** TODO #9100 */ = [];
var results: CssAst[] = [];
while (!characterContainsDelimiter(this._scanner.peek, delimiters)) {
results.push(this._parseRule(delimiters));
}
@ -770,7 +770,7 @@ export class CssParser {
this._scanner.setMode(CssLexerMode.STYLE_BLOCK);
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.
// 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'],
]);
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 lcProp = LIFECYCLE_PROPS.get(hook);
return reflector.hasLifecycleHook(token, lcInterface, lcProp);

View File

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

View File

@ -346,8 +346,8 @@ export class ApplicationRef_ extends ApplicationRef {
zone.run(() => { this._exceptionHandler = _injector.get(ExceptionHandler); });
this._asyncInitDonePromise = this.run(() => {
let inits: Function[] = _injector.get(APP_INITIALIZER, null);
var asyncInitResults: any[] /** TODO #9100 */ = [];
var asyncInitDonePromise: any /** TODO #9100 */;
var asyncInitResults: Promise<any>[] = [];
var asyncInitDonePromise: Promise<any>;
if (isPresent(inits)) {
for (var i = 0; i < inits.length; i++) {
var initResult = inits[i]();
@ -391,7 +391,7 @@ export class ApplicationRef_ extends ApplicationRef {
run(callback: Function): any {
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
// the thrown exception!
// Note: the completer needs to be created outside

View File

@ -51,7 +51,7 @@ import {stringify} from '../facade/lang';
* @stable
*/
export class InjectMetadata {
constructor(public token: any /** TODO #9100 */) {}
constructor(public token: any) {}
toString(): string { return `@Inject(${stringify(this.token)})`; }
}
@ -89,7 +89,7 @@ export class OptionalMetadata {
* @stable
*/
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: any /** TODO #9100 */;
token: any;
/**
* Binds a DI token to an implementation class.
@ -77,7 +77,7 @@ export class Provider {
* expect(injector.get("message")).toEqual('Hello');
* ```
*/
useValue: any /** TODO #9100 */;
useValue: any;
/**
* Binds a DI token to an existing token.
@ -111,7 +111,7 @@ export class Provider {
* 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.
@ -157,8 +157,7 @@ export class Provider {
/** @internal */
_multi: boolean;
constructor(
token: any /** TODO #9100 */, {useClass, useValue, useExisting, useFactory, deps, multi}: {
constructor(token: any, {useClass, useValue, useExisting, useFactory, deps, multi}: {
useClass?: Type,
useValue?: any,
useExisting?: any,
@ -215,7 +214,7 @@ export class Provider {
* @ts2dart_const
*/
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,
toValue?: any,
toAlias?: any,
@ -264,7 +263,7 @@ export class Binding extends Provider {
*
* @deprecated
*/
export function bind(token: any /** TODO #9100 */): ProviderBuilder {
export function bind(token: any): ProviderBuilder {
return new ProviderBuilder(token);
}
@ -273,7 +272,7 @@ export function bind(token: any /** TODO #9100 */): ProviderBuilder {
* @deprecated
*/
export class ProviderBuilder {
constructor(public token: any /** TODO #9100 */) {}
constructor(public token: any) {}
/**
* Binds a DI token to a class.
@ -398,15 +397,14 @@ export class ProviderBuilder {
* <!-- TODO: improve the docs -->
* @deprecated
*/
export function provide(
token: any /** TODO #9100 */, {useClass, useValue, useExisting, useFactory, deps, multi}: {
export function provide(token: any, {useClass, useValue, useExisting, useFactory, deps, multi}: {
useClass?: Type,
useValue?: any,
useExisting?: any,
useFactory?: Function,
deps?: Object[],
multi?: boolean
}): Provider {
}): Provider {
return new Provider(token, {
useClass: useClass,
useValue: useValue,

View File

@ -8,20 +8,20 @@
import {ListWrapper} from '../facade/collection';
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 {ReflectiveKey} from './reflective_key';
function findFirstClosedCycle(keys: any[]): any[] {
var res: any[] /** TODO #9100 */ = [];
var res: any[] = [];
for (var i = 0; i < keys.length; ++i) {
if (ListWrapper.contains(res, keys[i])) {
res.push(keys[i]);
return res;
} else {
res.push(keys[i]);
}
res.push(keys[i]);
}
return res;
}
@ -31,9 +31,9 @@ function constructResolvingPath(keys: any[]): string {
var reversed = findFirstClosedCycle(ListWrapper.reversed(keys));
var tokenStrs = reversed.map(k => stringify(k.token));
return ' (' + tokenStrs.join(' -> ') + ')';
} else {
return '';
}
return '';
}
@ -156,8 +156,8 @@ export class InstantiationError extends WrappedException {
injectors: ReflectiveInjector[];
constructor(
injector: ReflectiveInjector, originalException: any /** TODO #9100 */,
originalStack: any /** TODO #9100 */, key: ReflectiveKey) {
injector: ReflectiveInjector, originalException: any, originalStack: any,
key: ReflectiveKey) {
super('DI Exception', originalException, originalStack, null);
this.keys = [key];
this.injectors = [injector];
@ -190,7 +190,7 @@ export class InstantiationError extends WrappedException {
* @stable
*/
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}`);
}
}
@ -225,12 +225,12 @@ export class InvalidProviderError extends BaseException {
* @stable
*/
export class NoAnnotationError extends BaseException {
constructor(typeOrFunc: any /** TODO #9100 */, params: any[][]) {
constructor(typeOrFunc: Type|Function, params: any[][]) {
super(NoAnnotationError._genMessage(typeOrFunc, params));
}
private static _genMessage(typeOrFunc: any /** TODO #9100 */, params: any[][]) {
var signature: any[] /** TODO #9100 */ = [];
private static _genMessage(typeOrFunc: Type|Function, params: any[][]) {
var signature: string[] = [];
for (var i = 0, ii = params.length; i < ii; i++) {
var parameter = params[i];
if (isBlank(parameter) || parameter.length == 0) {
@ -261,7 +261,7 @@ export class NoAnnotationError extends BaseException {
* @stable
*/
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
@ -278,7 +278,7 @@ export class OutOfBoundsError extends BaseException {
* ```
*/
export class MixingMultiProvidersWithRegularProvidersError extends BaseException {
constructor(provider1: any /** TODO #9100 */, provider2: any /** TODO #9100 */) {
constructor(provider1: any, provider2: any) {
super(
'Cannot mix multi providers and regular providers, got: ' + provider1.toString() + ' ' +
provider2.toString());

View File

@ -739,7 +739,7 @@ export class ReflectiveInjector_ implements ReflectiveInjector {
throw e;
}
var obj: any /** TODO #9100 */;
var obj: any;
try {
switch (length) {
case 0:
@ -892,9 +892,9 @@ export class ReflectiveInjector_ implements ReflectiveInjector {
var INJECTOR_KEY = ReflectiveKey.get(Injector);
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) {
res.push(fn(injector._proto.getProviderAtIndex(i)));
res[i] = fn(injector._proto.getProviderAtIndex(i));
}
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}.
@ -105,13 +105,13 @@ export class ResolvedReflectiveFactory {
*/
export function resolveReflectiveFactory(provider: Provider): ResolvedReflectiveFactory {
var factoryFn: Function;
var resolvedDeps: any /** TODO #9100 */;
var resolvedDeps: ReflectiveDependency[];
if (isPresent(provider.useClass)) {
var useClass = resolveForwardRef(provider.useClass);
factoryFn = reflector.factory(useClass);
resolvedDeps = _dependenciesFor(useClass);
} else if (isPresent(provider.useExisting)) {
factoryFn = (aliasInstance: any /** TODO #9100 */) => aliasInstance;
factoryFn = (aliasInstance: any) => aliasInstance;
resolvedDeps = [ReflectiveDependency.fromKey(ReflectiveKey.get(provider.useExisting))];
} else if (isPresent(provider.useFactory)) {
factoryFn = provider.useFactory;
@ -169,7 +169,7 @@ export function mergeResolvedReflectiveProviders(
normalizedProvidersMap.set(provider.key.id, provider);
}
} else {
var resolvedProvider: any /** TODO #9100 */;
var resolvedProvider: ResolvedReflectiveProvider;
if (provider.multiProvider) {
resolvedProvider = new ResolvedReflectiveProvider_(
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
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 {