undefined
?cards: Cards = {}
card = this.cards[card_id] // Type 'undefined' cannot be used as an index type.
export interface Cards {
[x: string]: AnyCard
}
interface AnyCard {
id: string
value: string
}
Property 'undefined' of type 'undefined' is not assignable to 'string' index type 'AnyCard'.
export interface Cards {
[x: string]: AnyCard
undefined: undefined
}
undefined
не может быть ключом в принципе.card = card_id && this.cards[card_id];
card = this.cards[card_id!];
card = this.cards[String(card_id)];