Typescript 'type{}'和'Dictionary'之间的区别<;T>;{[key:string]:T;}`

Typescript 'type{}'和'Dictionary'之间的区别<;T>;{[key:string]:T;}`,typescript,typescript2.0,Typescript,Typescript2.0,异步库使用此声明 export interface Dictionary<T> { [key: string]: T; } ? 也许type{}允许将符号用于键,而字典接口只允许键是字符串 以下是异步的类型: 当使用--noImplicitAny时,上面字典接口中的索引签名将允许基于字符串的任意属性访问,而{}将不允许,因为它没有索引签名: interface Dictionary<T> { [key: string]: T; } let a: Dictionary&

异步库使用此声明

export interface Dictionary<T> { [key: string]: T; }
?

也许
type{}
允许将符号用于键,而字典接口只允许键是字符串

以下是异步的类型:

当使用
--noImplicitAny
时,上面
字典
接口中的索引签名将允许基于字符串的任意属性访问,而
{}
将不允许,因为它没有索引签名:

interface Dictionary<T> { [key: string]: T; }

let a: Dictionary<string> = {};
let b: {} = {};

a["one"] = "two"; // OK
b["two"] = "three"; // Not OK
接口字典{[key:string]:T;}
设a:Dictionary={};
设b:{}={};
a[“一”]=“两”//好啊
b[“两”]=“三”//不好

当未使用
--noImplicitAny
或使用
--suppressImplicitanIndexErrors
时,这不是问题,因为这样每个对象类型都被视为具有隐式“any to any”默认情况下的索引签名。

除了John Weisz的答案之外,还有一个巨大而明显的区别:
字典
允许您指定
T
{}
不指定。

谢谢,但是Symbol怎么办,对此有什么想法吗?可能提到相关的
抑制隐式索引错误
选项,也是?也许在幕后,符号属性总是被强制为字符串?我对符号不太熟悉,无法回答它们,但索引签名肯定是不同的。
interface Dictionary<T> { [key: string]: T; }

let a: Dictionary<string> = {};
let b: {} = {};

a["one"] = "two"; // OK
b["two"] = "three"; // Not OK