因此,我将 TypeScript 与 Angular 1.5 和 Angular 1.5 类型定义结合使用,但我不知道如何在 Angular 组件中定义绑定(bind)。
定义文件包含以下绑定(bind)内容
interface IComponentOptions {
...
bindings?: {[binding: string]: string};
...
}
但是我如何编写实际的 Javascript 对象呢?
.component('myComponent', {
templateUrl: 'template.html',
controller: MyController,
controllerAs: 'vm',
bindings: {
one: '<',
two: '<'
}
});
上面给了我
Type '{ one: string; two: string; }' is not assignable to type '{ [binding: string]: string; }'.
感谢所有回复!
最佳答案
Type '{ one: string; two: string; }' is not assignable to type '{ [binding: string]: string; }'
可能使用旧版本的 TypeScript。在最新的编译器中运行良好。
interface IComponentOptions {
bindings?: { [binding: string]: string };
}
var componentOptions: IComponentOptions = {
bindings: {
one: '<',
two: '<'
}
};
关于javascript - TypeScript 索引签名对象的格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37192071/