Answer the question
In order to leave comments, you need to log in
How to set the structure of an object in the interface, with a mandatory key and any number of another type?
There is such a structure for writing commands:
export interface cmd {
_about: string,
id: number,
}
export interface category {
_about: string,//Вот тут проблема
[cmd: string]: cmd
}
export interface cmdList {
[category: string]: category
}
const list: cmdList = {
system: {
_about: "Системные команды",
ok: {
_about: "Успешно принятая команда",
id: 0
},
err: {
_about: "Ошибка принятие команды",
id: 1
}
}
};
Answer the question
In order to leave comments, you need to log in
https://basarat.gitbooks.io/typescript/docs/types/... section "Excluding certain properties from the index signature"
In your case it will look like this .
It's better to construct this object differently:
{
system: {
_about: ...,
commands: {
ok: { ... },
err: { ... }
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question