How to represent a variable key name in typescript interface? How to represent a variable key name in typescript interface? typescript typescript

How to represent a variable key name in typescript interface?


Something like:

interface Item {    name: string;    price: string;}type Items = { [id: string]: Item }let items = {    34433ded : {name: "foo", price: 0.99},    14d433dee : {name: "bar", price: 1.99},} as Items;


You can achive this by following structure:

interface Items {    [key: string]: Item;}

Here is your fiddle.
But remember due to JSON specification your object keys should't begin with numbers or if they do - you have to wrap them in quotes (as I did in fiddle)