【发布时间】:2022-01-09 06:32:59
【问题描述】:
我不明白这段代码有什么问题。
这是我的代码:
export type SportsTypes = keyof typeof SportsIcons
export const sports: SportsTypes[] = Object.keys(SportsIcons);
我正在将我的变量键入到对象的键中。
但是,当我尝试将所述键的数组分配给这个变量时,我得到了 ts 错误:
Type 'string[]' is not assignable to type '("Football" | "GameController" | "Tennis" | "Basketball" | "PingPong" | "Volleyball" | "HockeyPuck" | "Chess" | "AmericanFootball" | "Baseball" | "SandVolleyball")[]
【问题讨论】:
标签: javascript reactjs typescript typeof keyof