Skip to content

Commit 208f3d4

Browse files
committed
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: microsoft/TypeScript#5089 Closes angular#4487
1 parent 7c4199c commit 208f3d4

File tree

16 files changed

+36
-36
lines changed

16 files changed

+36
-36
lines changed

modules/angular2/src/core/compiler/directive_metadata.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ export class CompileDirectiveMetadata {
113113
lifecycleHooks?: LifecycleHooks[],
114114
template?: CompileTemplateMetadata
115115
} = {}): CompileDirectiveMetadata {
116-
var hostListeners = {};
117-
var hostProperties = {};
118-
var hostAttributes = {};
116+
var hostListeners: {[key: string]: string} = {};
117+
var hostProperties: {[key: string]: string} = {};
118+
var hostAttributes: {[key: string]: string} = {};
119119
if (isPresent(host)) {
120120
StringMapWrapper.forEach(host, (value: string, key: string) => {
121121
var matches = RegExpWrapper.firstMatch(HOST_REG_EXP, key);
@@ -128,7 +128,7 @@ export class CompileDirectiveMetadata {
128128
}
129129
});
130130
}
131-
var inputsMap = {};
131+
var inputsMap: {[key: string]: string} = {};
132132
if (isPresent(inputs)) {
133133
inputs.forEach((bindConfig: string) => {
134134
// canonical syntax: `dirProp: elProp`
@@ -137,7 +137,7 @@ export class CompileDirectiveMetadata {
137137
inputsMap[parts[0]] = parts[1];
138138
});
139139
}
140-
var outputsMap = {};
140+
var outputsMap: {[key: string]: string} = {};
141141
if (isPresent(outputs)) {
142142
outputs.forEach((bindConfig: string) => {
143143
// canonical syntax: `dirProp: elProp`

modules/angular2/src/core/dom/generic_browser_adapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export abstract class GenericBrowserDomAdapter extends DomAdapter {
2323
}
2424
}
2525
}
26-
var transEndEventNames = {
26+
var transEndEventNames: {[key: string]: string} = {
2727
WebkitTransition: 'webkitTransitionEnd',
2828
MozTransition: 'transitionend',
2929
OTransition: 'oTransitionEnd otransitionend',

modules/angular2/src/core/dom/parse5_adapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
import {BaseException, WrappedException} from 'angular2/src/core/facade/exceptions';
1818
import {SelectorMatcher, CssSelector} from 'angular2/src/core/compiler/selector';
1919

20-
var _attrToPropMap = {
20+
var _attrToPropMap: {[key: string]: string} = {
2121
'class': 'className',
2222
'innerHtml': 'innerHTML',
2323
'readonly': 'readOnly',

modules/angular2/src/core/facade/collection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export class MapWrapper {
8686
return result;
8787
}
8888
static toStringMap<T>(m: Map<string, T>): {[key: string]: T} {
89-
var r = {};
89+
var r: {[key: string]: T} = {};
9090
m.forEach((v, k) => r[k] = v);
9191
return r;
9292
}
@@ -135,7 +135,7 @@ export class StringMapWrapper {
135135
}
136136

137137
static merge<V>(m1: {[key: string]: V}, m2: {[key: string]: V}): {[key: string]: V} {
138-
var m = {};
138+
var m: {[key: string]: V} = {};
139139

140140
for (var attr in m1) {
141141
if (m1.hasOwnProperty(attr)) {

modules/angular2/src/core/forms/form_builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export class FormBuilder {
9797
}
9898

9999
_reduceControls(controlsConfig: any): {[key: string]: modelModule.AbstractControl} {
100-
var controls = {};
100+
var controls: {[key: string]: modelModule.AbstractControl} = {};
101101
StringMapWrapper.forEach(controlsConfig, (controlConfig, controlName) => {
102102
controls[controlName] = this._createControl(controlConfig);
103103
});

modules/angular2/src/core/forms/validators.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ export class Validators {
2929
return function(control: modelModule.Control) {
3030
var res = ListWrapper.reduce(validators, (res, validator) => {
3131
var errors = validator(control);
32-
return isPresent(errors) ? StringMapWrapper.merge(res, errors) : res;
32+
return isPresent(errors) ? StringMapWrapper.merge(<any>res, <any>errors) : res;
3333
}, {});
3434
return StringMapWrapper.isEmpty(res) ? null : res;
3535
};
3636
}
3737

38-
static group(group: modelModule.ControlGroup): {[key: string]: boolean} {
39-
var res = {};
38+
static group(group: modelModule.ControlGroup): {[key: string]: any[]} {
39+
var res: {[key: string]: any[]} = {};
4040
StringMapWrapper.forEach(group.controls, (control, name) => {
4141
if (group.contains(name) && isPresent(control.errors)) {
4242
Validators._mergeErrors(control, res);
@@ -45,8 +45,8 @@ export class Validators {
4545
return StringMapWrapper.isEmpty(res) ? null : res;
4646
}
4747

48-
static array(array: modelModule.ControlArray): {[key: string]: boolean} {
49-
var res = {};
48+
static array(array: modelModule.ControlArray): {[key: string]: any[]} {
49+
var res: {[key: string]: any[]} = {};
5050
array.controls.forEach((control) => {
5151
if (isPresent(control.errors)) {
5252
Validators._mergeErrors(control, res);

modules/angular2/src/core/linker/directive_resolver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ export class DirectiveResolver {
4646
propertyMetadata: {[key: string]: any[]}): DirectiveMetadata {
4747
var inputs = [];
4848
var outputs = [];
49-
var host = {};
50-
var queries = {};
49+
var host: {[key: string]: string} = {};
50+
var queries: {[key: string]: any} = {};
5151

5252
StringMapWrapper.forEach(propertyMetadata, (metadata: any[], propName: string) => {
5353
metadata.forEach(a => {

modules/angular2/src/core/linker/proto_view_factory.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ export class ProtoViewFactory {
5555
var result = this._cache.get(compiledTemplate.id);
5656
if (isBlank(result)) {
5757
var templateData = compiledTemplate.getData(this._appId);
58-
result =
59-
new AppProtoView(templateData.commands, ViewType.HOST, true,
60-
templateData.changeDetectorFactory, null, new ProtoPipes(new Map()));
58+
var emptyMap: {[key: string]: PipeBinding} = {};
59+
result = new AppProtoView(templateData.commands, ViewType.HOST, true,
60+
templateData.changeDetectorFactory, null, new ProtoPipes(emptyMap));
6161
this._cache.set(compiledTemplate.id, result);
6262
}
6363
return result;

modules/angular2/src/core/pipes/date_pipe.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ var defaultLocale: string = 'en-US';
8181
@Pipe({name: 'date'})
8282
@Injectable()
8383
export class DatePipe implements PipeTransform {
84-
static _ALIASES = {
84+
static _ALIASES: {[key: string]: String} = {
8585
'medium': 'yMMMdjms',
8686
'short': 'yMdjm',
8787
'fullDate': 'yMMMMEEEEd',

modules/angular2/src/core/pipes/pipes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import * as cd from 'angular2/src/core/change_detection/pipes';
1414

1515
export class ProtoPipes {
1616
static fromBindings(bindings: PipeBinding[]): ProtoPipes {
17-
var config = {};
17+
var config: {[key: string]: PipeBinding} = {};
1818
bindings.forEach(b => config[b.name] = b);
1919
return new ProtoPipes(config);
2020
}

0 commit comments

Comments
 (0)