Answer the question
In order to leave comments, you need to log in
How to set the type of the interface key in the interface?
There is an array of modules, how to limit the parent parameter to an array of keys of the same array (or another)?
export interface module {
_about: string,
parent?: modules.moduleID//Вот тут ошибка
}
export interface modules {
[moduleID: number]: module
}
const list: modules = {
0: {
_about: "Root",
},
1: {
_about: "Child",
parent: 0 //Нужно ограничить до 0 | 1
}
};
Answer the question
In order to leave comments, you need to log in
unfortunately this cannot be done, the type cannot know in any way what keys will be in an object of this type
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question