【发布时间】:2020-12-28 09:40:38
【问题描述】:
我有这样的设置:
enum PokemonType {
Dark = "DARK"
Light = "Light"
}
const pokemonTypes: {[key: string]: PokemonInfo} = {
"DARK": {
info: "Dark is bad",
color: "black"
},
"Light": {
info: "Light is good",
color: "white"
}
}
interface Pokemon {
type: PokemonType,
// !!Some kind of function here to use type
// to index into pokemonTypes.!!
}
请参阅上面Pokemon 中的评论。基本上我希望Pokemon 接口中的一个函数使用type 键来索引pokemonTypes const。我怎么能这样做?谢谢!
【问题讨论】:
标签: reactjs typescript