34
interface Items {
    id: Item,
}

id is not optional but it will have different name

for example:

let items = {
34433ded : {name: "foo", price: 0.99},
14d433dee : {name: "bar", price: 1.99},
}

2 Answers 2

45

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;
Sign up to request clarification or add additional context in comments.

Comments

22

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.