N
N
Neuro2022-03-12 16:55:40
typescript
Neuro, 2022-03-12 16:55:40

How to combine multiple types into one interface?

Good afternoon, maybe someone knows how I can create an interface of this kind:

interface StageState {
    [key: string]: Product[]; // *
    mode: string;
    categoryKey: string;
};

I have an object that stores the properties mode, categoryKey, and n a number of other properties with unknown names, it is only known that the remaining properties will always have the same type.

This example is incorrect and throws an error:
622ca64981c85752678510.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Ne7Le4Der, 2022-03-16
@Riveran

I can’t tell you how to do this using interface, I will be glad if someone tells you, but you can implement something like this using type:

type StageState = {
    mode: string; 
    categoryKey: string
} & Record<string, Product[]>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question