[英]TypeScript's hashtables and keys with a dash
Is it possible to declare a hashtable which includes keys with a dash in TypeScript? 是否可以在TypeScript中声明包含带短划线的键的哈希表?
Here's the code i've tried: 这是我试过的代码:
export interface ImapMessageHeader {
'mime-version': string[];
received: string[];
[index: string]: string[];
}
From which i receive the following error: 从中我收到以下错误:
Expected identifier in property declaration
财产申报中的预期标识符
The last declaration defining the index type allows me to call any string key, but i can't explicitly define the ones i want to use. 定义索引类型的最后一个声明允许我调用任何字符串键,但我无法明确定义我想要使用的键。
Thanks! 谢谢!
This works for me in TypeScript 0.9.5. 这适用于TypeScript 0.9.5。 The issue is marked as close too.
该问题也被标记为接近 。
interface Foo
{
"a-1": string;
}
var f: Foo = { "a-1": "hello" };
尚未支持接口声明和类型文字中的引用属性名称,但我相信它们将在未来版本中添加。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.