Typescript 为什么长度应该是索引器的子类型?

Typescript 为什么长度应该是索引器的子类型?,typescript,typescript1.4,Typescript,Typescript1.4,我在的TypeScript手册中看到了一个例子。 我不明白为什么length属性无效 interface Dictionary { [index: string]: string; length: number; // error, the type of 'length' is not a subtype of the indexer } 因为x['length']是一个数字,但您说过索引xstring会生成一个字符串。它们不可能都是真的。那么属性是否像JavaScript一

我在的TypeScript手册中看到了一个例子。 我不明白为什么
length
属性无效

interface Dictionary {
  [index: string]: string;
  length: number;    // error, the type of 'length' is not a subtype of the indexer
} 

因为
x['length']
是一个数字,但您说过索引
x
string会生成一个字符串。它们不可能都是真的。

那么属性是否像JavaScript一样可以通过类似字典的方式访问呢!?TypeScript是JavaScript的语法超集。