F
F
fif2022-01-22 12:48:15
typescript
fif, 2022-01-22 12:48:15

How to write an interface for an object?

I have such an object with links names and prices.

const asideBlock = {
    links: {
        0 : "../images/shop/wells/well-01.png",
        1 : "../images/shop/depots/depot-01.png",
        2 : "../images/shop/cages/cage-01.png"
    },
    nameCost: {
        "Колодец" : "200",
        "Склад" : "150",
        "Клетка" : "100",
    }
};


I need an interface for the whole object, I tried to do something but it did not help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2022-01-22
@fif

Something like this:

interface AsideBlock {
    links: Record<number, string>;
    nameCost: Record<string, `${number}`>;
}

const asideBlock: AsideBlock = {
    links: {
        0 : "../images/shop/wells/well-01.png",
        1 : "../images/shop/depots/depot-01.png",
        2 : "../images/shop/cages/cage-01.png"
    },
    nameCost: {
        "Колодец" : "200",
        "Склад" : "150",
        "Клетка" : "100",
    }
};

But Lynn "Coffeeman" is right: the structure is complete garbage and hands off for such a thing.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question