все! Пожалуйста, помогите мне решить мою проблему. У меня есть объект с функциями, где ключи равны имени типа в объекте с данными. но я не могу заставить поток понять это правильно. Есть ли способ аннотировать такие случаи?
const obj = {
type1: func1,
type2: func2
}
type Type1 = 'type1';
type Type2 = 'type2';
type Item1 = {
type: Type1,
dataInItem1: string
}
type Item2 = {
type: Type2,
dataInItem2: string
}
const item1: Item1 = {
type: 'type1',
dataInItem1: 'dataInItem1'
}
const item2: Item2 = {
type: 'type2',
dataInItem2: 'dataInItem2'
}
const getItemByPropType = (item: Item1 | Item2, obj) => {
return obj[item.type](item)
}
Cannot call getItemByPropType with item bound to the first parameter because:
• all branches are incompatible:
• Either property dataInItem2 is missing in Item1 [1] but exists in Item2