Cannot invoke an expression whose type lacks a call signature
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have apple and pears - both have an isDecayed attribute: interface Apple { color: string; isDecayed: boolean; } interface Pear { weight: number; isDecayed: boolean; } And both types can be in my fruit basket (multiple times): interface FruitBasket { apples: Apple[]; pears: Pear[]; } Let's assume for now my basket is empty: const fruitBasket: FruitBasket = { apples: [], pears: [] }; Now we take randomly one kind out of the basket: const key: keyof FruitBasket = Math.random() > 0.5 ? 'apples': 'pears'; const fruits = fruitBasket[key]; And of