lundi 13 février 2017

Typescript: How do I define interfaces for nested objects?

Vote count: 0

Assume I have a JSON payload that parses into something like this:

{
    name: "test",
    items: {
        "a": {
            id: 1,
            size: 10
        },
        "b": {
            id: 2,
            size: 34
        }
    }
}

How would I set up the definition of the Example interface to model that the value of the items property is an object whose keys are strings and whose values are defined by the Item interface:

export interface Example {
    name: string;
    items: ???;

}

export interface Item {
    id: number;
    size: number;
}

asked 40 secs ago

Let's block ads! (Why?)



Typescript: How do I define interfaces for nested objects?

Aucun commentaire:

Enregistrer un commentaire