19

Is it possible to declare a hashtable which includes keys with a dash in 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!

4

2 回答 2

22

这在 TypeScript 0.9.5 中适用于我。该问题也被标记为关闭

interface Foo
{
    "a-1": string;
}

var f: Foo = { "a-1": "hello" };
于 2014-02-25T18:15:40.780 回答
3

Quoted property names in interface declarations and type literals aren't supported yet, but I believe they will be added in a future release.

于 2012-12-01T19:40:00.630 回答