fix(typings): repair broken type-checking for StringMap
Note that the previous type of StringMap was overly permissive and didn't catch errors. Also we have to explicitly type empty objects, which is explained here: https://github.com/Microsoft/TypeScript/issues/5089 Closes #4487
This commit is contained in:
parent
7c4199cd1c
commit
208f3d4c65
|
@ -113,9 +113,9 @@ export class CompileDirectiveMetadata {
|
|||
lifecycleHooks?: LifecycleHooks[],
|
||||
template?: CompileTemplateMetadata
|
||||
} = {}): CompileDirectiveMetadata {
|
||||
var hostListeners = {};
|
||||
var hostProperties = {};
|
||||
var hostAttributes = {};
|
||||
var hostListeners: {[key: string]: string} = {};
|
||||
var hostProperties: {[key: string]: string} = {};
|
||||
var hostAttributes: {[key: string]: string} = {};
|
||||
if (isPresent(host)) {
|
||||
StringMapWrapper.forEach(host, (value: string, key: string) => {
|
||||
var matches = RegExpWrapper.firstMatch(HOST_REG_EXP, key);
|
||||
|
@ -128,7 +128,7 @@ export class CompileDirectiveMetadata {
|
|||
}
|
||||
});
|
||||
}
|
||||
var inputsMap = {};
|
||||
var inputsMap: {[key: string]: string} = {};
|
||||
if (isPresent(inputs)) {
|
||||
inputs.forEach((bindConfig: string) => {
|
||||
// canonical syntax: `dirProp: elProp`
|
||||
|
@ -137,7 +137,7 @@ export class CompileDirectiveMetadata {
|
|||
inputsMap[parts[0]] = parts[1];
|
||||
});
|
||||
}
|
||||
var outputsMap = {};
|
||||
var outputsMap: {[key: string]: string} = {};
|
||||
if (isPresent(outputs)) {
|
||||
outputs.forEach((bindConfig: string) => {
|
||||
// canonical syntax: `dirProp: elProp`
|
||||
|
|
|
@ -23,7 +23,7 @@ export abstract class GenericBrowserDomAdapter extends DomAdapter {
|
|||
}
|
||||
}
|
||||
}
|
||||
var transEndEventNames = {
|
||||
var transEndEventNames: {[key: string]: string} = {
|
||||
WebkitTransition: 'webkitTransitionEnd',
|
||||
MozTransition: 'transitionend',
|
||||
OTransition: 'oTransitionEnd otransitionend',
|
||||
|
|
|
@ -17,7 +17,7 @@ import {
|
|||
import {BaseException, WrappedException} from 'angular2/src/core/facade/exceptions';
|
||||
import {SelectorMatcher, CssSelector} from 'angular2/src/core/compiler/selector';
|
||||
|
||||
var _attrToPropMap = {
|
||||
var _attrToPropMap: {[key: string]: string} = {
|
||||
'class': 'className',
|
||||
'innerHtml': 'innerHTML',
|
||||
'readonly': 'readOnly',
|
||||
|
|
|
@ -86,7 +86,7 @@ export class MapWrapper {
|
|||
return result;
|
||||
}
|
||||
static toStringMap<T>(m: Map<string, T>): {[key: string]: T} {
|
||||
var r = {};
|
||||
var r: {[key: string]: T} = {};
|
||||
m.forEach((v, k) => r[k] = v);
|
||||
return r;
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ export class StringMapWrapper {
|
|||
}
|
||||
|
||||
static merge<V>(m1: {[key: string]: V}, m2: {[key: string]: V}): {[key: string]: V} {
|
||||
var m = {};
|
||||
var m: {[key: string]: V} = {};
|
||||
|
||||
for (var attr in m1) {
|
||||
if (m1.hasOwnProperty(attr)) {
|
||||
|
|
|
@ -97,7 +97,7 @@ export class FormBuilder {
|
|||
}
|
||||
|
||||
_reduceControls(controlsConfig: any): {[key: string]: modelModule.AbstractControl} {
|
||||
var controls = {};
|
||||
var controls: {[key: string]: modelModule.AbstractControl} = {};
|
||||
StringMapWrapper.forEach(controlsConfig, (controlConfig, controlName) => {
|
||||
controls[controlName] = this._createControl(controlConfig);
|
||||
});
|
||||
|
|
|
@ -29,14 +29,14 @@ export class Validators {
|
|||
return function(control: modelModule.Control) {
|
||||
var res = ListWrapper.reduce(validators, (res, validator) => {
|
||||
var errors = validator(control);
|
||||
return isPresent(errors) ? StringMapWrapper.merge(res, errors) : res;
|
||||
return isPresent(errors) ? StringMapWrapper.merge(<any>res, <any>errors) : res;
|
||||
}, {});
|
||||
return StringMapWrapper.isEmpty(res) ? null : res;
|
||||
};
|
||||
}
|
||||
|
||||
static group(group: modelModule.ControlGroup): {[key: string]: boolean} {
|
||||
var res = {};
|
||||
static group(group: modelModule.ControlGroup): {[key: string]: any[]} {
|
||||
var res: {[key: string]: any[]} = {};
|
||||
StringMapWrapper.forEach(group.controls, (control, name) => {
|
||||
if (group.contains(name) && isPresent(control.errors)) {
|
||||
Validators._mergeErrors(control, res);
|
||||
|
@ -45,8 +45,8 @@ export class Validators {
|
|||
return StringMapWrapper.isEmpty(res) ? null : res;
|
||||
}
|
||||
|
||||
static array(array: modelModule.ControlArray): {[key: string]: boolean} {
|
||||
var res = {};
|
||||
static array(array: modelModule.ControlArray): {[key: string]: any[]} {
|
||||
var res: {[key: string]: any[]} = {};
|
||||
array.controls.forEach((control) => {
|
||||
if (isPresent(control.errors)) {
|
||||
Validators._mergeErrors(control, res);
|
||||
|
|
|
@ -46,8 +46,8 @@ export class DirectiveResolver {
|
|||
propertyMetadata: {[key: string]: any[]}): DirectiveMetadata {
|
||||
var inputs = [];
|
||||
var outputs = [];
|
||||
var host = {};
|
||||
var queries = {};
|
||||
var host: {[key: string]: string} = {};
|
||||
var queries: {[key: string]: any} = {};
|
||||
|
||||
StringMapWrapper.forEach(propertyMetadata, (metadata: any[], propName: string) => {
|
||||
metadata.forEach(a => {
|
||||
|
|
|
@ -55,9 +55,9 @@ export class ProtoViewFactory {
|
|||
var result = this._cache.get(compiledTemplate.id);
|
||||
if (isBlank(result)) {
|
||||
var templateData = compiledTemplate.getData(this._appId);
|
||||
result =
|
||||
new AppProtoView(templateData.commands, ViewType.HOST, true,
|
||||
templateData.changeDetectorFactory, null, new ProtoPipes(new Map()));
|
||||
var emptyMap: {[key: string]: PipeBinding} = {};
|
||||
result = new AppProtoView(templateData.commands, ViewType.HOST, true,
|
||||
templateData.changeDetectorFactory, null, new ProtoPipes(emptyMap));
|
||||
this._cache.set(compiledTemplate.id, result);
|
||||
}
|
||||
return result;
|
||||
|
|
|
@ -81,7 +81,7 @@ var defaultLocale: string = 'en-US';
|
|||
@Pipe({name: 'date'})
|
||||
@Injectable()
|
||||
export class DatePipe implements PipeTransform {
|
||||
static _ALIASES = {
|
||||
static _ALIASES: {[key: string]: String} = {
|
||||
'medium': 'yMMMdjms',
|
||||
'short': 'yMdjm',
|
||||
'fullDate': 'yMMMMEEEEd',
|
||||
|
|
|
@ -14,7 +14,7 @@ import * as cd from 'angular2/src/core/change_detection/pipes';
|
|||
|
||||
export class ProtoPipes {
|
||||
static fromBindings(bindings: PipeBinding[]): ProtoPipes {
|
||||
var config = {};
|
||||
var config: {[key: string]: PipeBinding} = {};
|
||||
bindings.forEach(b => config[b.name] = b);
|
||||
return new ProtoPipes(config);
|
||||
}
|
||||
|
|
|
@ -251,7 +251,7 @@ export class NgZone {
|
|||
var errorHandling;
|
||||
|
||||
if (enableLongStackTrace) {
|
||||
errorHandling = StringMapWrapper.merge(Zone.longStackTraceZone,
|
||||
errorHandling = StringMapWrapper.merge(<any>Zone.longStackTraceZone,
|
||||
{onError: function(e) { ngZone._onError(this, e); }});
|
||||
} else {
|
||||
errorHandling = {onError: function(e) { ngZone._onError(this, e); }};
|
||||
|
|
|
@ -44,7 +44,7 @@ export class Headers {
|
|||
if (headers instanceof Headers) {
|
||||
this._headersMap = (<Headers>headers)._headersMap;
|
||||
} else /*if (headers instanceof StringMap)*/ {
|
||||
this._headersMap = MapWrapper.createFromStringMap<string[]>(headers);
|
||||
this._headersMap = MapWrapper.createFromStringMap<string[]>(<{[key: string]: any}>headers);
|
||||
MapWrapper.forEach(this._headersMap, (v, k) => {
|
||||
if (!isListLikeIterable(v)) {
|
||||
var list = [];
|
||||
|
|
|
@ -155,7 +155,7 @@ export class RouteRegistry {
|
|||
}
|
||||
|
||||
var componentRecognizer = this._rules.get(parentComponent);
|
||||
var auxInstructions = {};
|
||||
var auxInstructions: {[key: string]: Instruction} = {};
|
||||
|
||||
var promises = instruction.auxUrls.map((auxSegment: Url) => {
|
||||
var match = componentRecognizer.recognizeAuxiliary(auxSegment);
|
||||
|
|
|
@ -109,33 +109,33 @@ export function main() {
|
|||
() => { expect(StringMapWrapper.equals({}, {})).toBe(true); });
|
||||
|
||||
it('should return true when comparing the same map', () => {
|
||||
var m1 = {'a': 1, 'b': 2, 'c': 3};
|
||||
var m1: {[key: string]: number} = {'a': 1, 'b': 2, 'c': 3};
|
||||
expect(StringMapWrapper.equals(m1, m1)).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true when comparing different maps with the same keys and values', () => {
|
||||
var m1 = {'a': 1, 'b': 2, 'c': 3};
|
||||
var m2 = {'a': 1, 'b': 2, 'c': 3};
|
||||
var m1: {[key: string]: number} = {'a': 1, 'b': 2, 'c': 3};
|
||||
var m2: {[key: string]: number} = {'a': 1, 'b': 2, 'c': 3};
|
||||
expect(StringMapWrapper.equals(m1, m2)).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false when comparing maps with different numbers of keys', () => {
|
||||
var m1 = {'a': 1, 'b': 2, 'c': 3};
|
||||
var m2 = {'a': 1, 'b': 2, 'c': 3, 'd': 4};
|
||||
var m1: {[key: string]: number} = {'a': 1, 'b': 2, 'c': 3};
|
||||
var m2: {[key: string]: number} = {'a': 1, 'b': 2, 'c': 3, 'd': 4};
|
||||
expect(StringMapWrapper.equals(m1, m2)).toBe(false);
|
||||
expect(StringMapWrapper.equals(m2, m1)).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false when comparing maps with different keys', () => {
|
||||
var m1 = {'a': 1, 'b': 2, 'c': 3};
|
||||
var m2 = {'a': 1, 'b': 2, 'CC': 3};
|
||||
var m1: {[key: string]: number} = {'a': 1, 'b': 2, 'c': 3};
|
||||
var m2: {[key: string]: number} = {'a': 1, 'b': 2, 'CC': 3};
|
||||
expect(StringMapWrapper.equals(m1, m2)).toBe(false);
|
||||
expect(StringMapWrapper.equals(m2, m1)).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false when comparing maps with different values', () => {
|
||||
var m1 = {'a': 1, 'b': 2, 'c': 3};
|
||||
var m2 = {'a': 1, 'b': 20, 'c': 3};
|
||||
var m1: {[key: string]: number} = {'a': 1, 'b': 2, 'c': 3};
|
||||
var m2: {[key: string]: number} = {'a': 1, 'b': 20, 'c': 3};
|
||||
expect(StringMapWrapper.equals(m1, m2)).toBe(false);
|
||||
expect(StringMapWrapper.equals(m2, m1)).toBe(false);
|
||||
});
|
||||
|
|
|
@ -187,7 +187,7 @@ export function main() {
|
|||
}
|
||||
];
|
||||
|
||||
browsers.forEach((browser) => {
|
||||
browsers.forEach((browser: {[key: string]: any}) => {
|
||||
it(`should detect ${StringMapWrapper.get(browser, 'name')}`, () => {
|
||||
var bd = new BrowserDetection(<string>StringMapWrapper.get(browser, 'ua'));
|
||||
expect(bd.isFirefox).toBe(StringMapWrapper.get(browser, 'isFirefox'));
|
||||
|
|
|
@ -77,7 +77,7 @@ class MockMetric extends Metric {
|
|||
}
|
||||
|
||||
describe(): {[key: string]: string} {
|
||||
var result = {};
|
||||
var result: {[key: string]: string} = {};
|
||||
result[this._id] = 'describe';
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue