12

Hello how can I solve this problem? I have an array of components but I can not use "any" type. So what type component has and how can I overcome this error?

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;
1
  • 1
    const stars: React.ReactElement[] = [] ? Commented Mar 2, 2022 at 19:12

1 Answer 1

28
const stars: React.ReactElement[] = [];
Sign up to request clarification or add additional context in comments.

2 Comments

Yeah that is thanks Sir! :)
You're welcome! You can click the tick next to the answer to mark it as accepted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.