4

Closed

quoted property names in interface declarations

description

Lots of JSON that I want to create an interface declaration for uses hyphens in the name. Unfortunately, this is not allowed in an identifier.

An example is mapping to the JSON returned from the Spotify Metadata API. I can't seem to map "artist-id". I've tried a couple of things:

https://developer.spotify.com/technologies/web-api/

export interface Album {
//artist-id: string;
//artist\u002did: string;
//"artist-id": string;
name: string;
artist: string;
//external-ids: ExternalId[];
released: string;
tracks: Track[];
href: string;
availability: Availability;
}

This was also brought up on stackoverflow here:
http://stackoverflow.com/questions/13661144/typescripts-hashtables-and-keys-with-a-dash
Closed May 31, 2013 at 1:09 AM by danquirk
This works in the latest bits. There is a bug where we are not resolving the type correctly (i.e. when you access albumInstance['artist-id'] you get a value of type any instead of string) but quoted property names are supported in type declarations now.

comments

nogece2 wrote Sep 1, 2013 at 4:38 PM

I tried this by typing the following into the playground. It shows errors. Doesnt seem to work.
interface X {
    'a-b':string;
}

var x:X = {
    "a-b":"haha"
}

paulb wrote Sep 6, 2013 at 10:32 PM

This is fixed in the develop branch.