Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript's hashtables and keys with a dash

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!

like image 993
Tobias Cudnik Avatar asked Dec 01 '12 16:12

Tobias Cudnik


Video Answer


2 Answers

This works for me in TypeScript 0.9.5. The issue is marked as close too.

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

var f: Foo = { "a-1": "hello" };
like image 150
Drew Noakes Avatar answered Oct 15 '22 11:10

Drew Noakes


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

like image 33
Ryan Cavanaugh Avatar answered Oct 15 '22 10:10

Ryan Cavanaugh