0

I do not understand what the problem is with this code.

Here is my code:

export type SportsTypes = keyof typeof SportsIcons

export const sports: SportsTypes[] = Object.keys(SportsIcons);

I am typing my variable to the keys of an object. But, when I then try to assign an array of said keys to this variable, I get the ts error: Type 'string[]' is not assignable to type '("Football" | "GameController" | "Tennis" | "Basketball" | "PingPong" | "Volleyball" | "HockeyPuck" | "Chess" | "AmericanFootball" | "Baseball" | "SandVolleyball")[]


export type SportsTypes = keyof typeof SportsIcons

export const sports = Object.keys(SportsIcons) as SportsTypes[];
4

1 回答 1

1
export type SportsTypes = keyof typeof SportsIcons

export const sports = Object.keys(SportsIcons) as SportsTypes[];
于 2021-12-02T18:58:31.237 回答