React-typescript 和渲染组件数组

Kay*_*Kay 7 typescript reactjs

您好,我该如何解决这个问题?我有一系列组件,但不能使用“任何”类型。那么什么类型的组件有什么类型以及如何克服这个错误?

Variable 'stars' implicitly has type 'any[]' in some locations where its type cannot be determined.
Variable 'stars' implicitly has an 'any[]' type.

import { StarIcon } from "@chakra-ui/icons";

interface recipeDesc {
  recipe: Recipe;
}

const stars = [];
const NUMBER_OF_STARS = 5;
let starLimit = 0;

while (starLimit > NUMBER_OF_STARS) {
  starLimit++;
  stars.push(<StarIcon />);
}

const RecipeDescription: React.FC<recipeDesc> = (props) => {
  return (
    <Box marginLeft="2rem">
      <Text fontSize="4rem" fontWeight="700">
        {props.recipe.title}
      </Text>
      {stars}
    </Box>
  );
};

export default RecipeDescription;
Run Code Online (Sandbox Code Playgroud)

Ana*_*sia 22

const stars: React.ReactElement[] = [];
Run Code Online (Sandbox Code Playgroud)