更新了我的 Typescript 定义,破坏了 angular 指令
Updated my Typescript definitions, broke angular directive
我刚刚将我的 Typescript 定义更新为今天可用的最新版本。在 angular.d.ts
中,现在是来自 IDirective
接口的 scope
的定义:
interface IDirective {
...
scope?: boolean | {[boundProperty: string]: string};
...
}
我的指令是这样定义的(用字母代替实际名称并省略了不相关的代码):
export class MyDirective implements angular.IDirective {
scope = {
a: "&",
b: "@?",
c: "=?",
d: "=?",
e: "@?",
}
}
我遇到这个编译时错误:
Error Class 'MyDirective' incorrectly implements interface 'IDirective'.
Types of property 'scope' are incompatible.
Type '{ a: string; b: string; c: string; d: string; e: string; }' is not assignable to type 'boolean | { [boundProperty: string]: string; }'.
Type '{ a: string; b: string; c: string; d: string; e: string; }' is not assignable to type '{ [boundProperty: string]: string; }'.
Index signature is missing in type '{ a: string; b: string; c: string; d: string; e: string; }'.
我不明白为什么我会收到这个。每个属性都是一个字符串,这就是 { [boundProperty: string]: string; }
部分想要的,不是吗?
如何更改范围定义以适应更新后的定义?
我试过你的代码,它可以很好地转换。我会关闭并重新启动您正在使用的 IDE 并查看此错误是否消失;当 TypeScript 错误没有意义时,作为 Visual Studio 用户,这对我来说似乎很常见。
如果这不起作用,请确保将您的 TypeScript 编译器版本更新到最新版本。
我知道这不是最新的,但这是我正在使用的输入:注册表:dt/angular#1.5.0+20161101124950
我的 TypeScript 版本:2.1.5.0
我刚刚将我的 Typescript 定义更新为今天可用的最新版本。在 angular.d.ts
中,现在是来自 IDirective
接口的 scope
的定义:
interface IDirective {
...
scope?: boolean | {[boundProperty: string]: string};
...
}
我的指令是这样定义的(用字母代替实际名称并省略了不相关的代码):
export class MyDirective implements angular.IDirective {
scope = {
a: "&",
b: "@?",
c: "=?",
d: "=?",
e: "@?",
}
}
我遇到这个编译时错误:
Error Class 'MyDirective' incorrectly implements interface 'IDirective'. Types of property 'scope' are incompatible.
Type '{ a: string; b: string; c: string; d: string; e: string; }' is not assignable to type 'boolean | { [boundProperty: string]: string; }'.
Type '{ a: string; b: string; c: string; d: string; e: string; }' is not assignable to type '{ [boundProperty: string]: string; }'.
Index signature is missing in type '{ a: string; b: string; c: string; d: string; e: string; }'.
我不明白为什么我会收到这个。每个属性都是一个字符串,这就是 { [boundProperty: string]: string; }
部分想要的,不是吗?
如何更改范围定义以适应更新后的定义?
我试过你的代码,它可以很好地转换。我会关闭并重新启动您正在使用的 IDE 并查看此错误是否消失;当 TypeScript 错误没有意义时,作为 Visual Studio 用户,这对我来说似乎很常见。
如果这不起作用,请确保将您的 TypeScript 编译器版本更新到最新版本。
我知道这不是最新的,但这是我正在使用的输入:注册表:dt/angular#1.5.0+20161101124950 我的 TypeScript 版本:2.1.5.0