Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

294
Views
La propiedad 'id' no existe en el tipo 'nunca'. mecanografiado

Intenté mostrar la imagen de JSON api y luego mostrarla en la página, lo hice con éxito, pero por alguna razón, cuando voy a la página, aparece este error.

 Property 'id' does not exist on type 'never'. Property 'url' does not exist on type 'never'. Property 'title' does not exist on type 'never'.

aquí está el código

 const App = () => { const [images, setImages] = useState([]); useEffect(() => { fetch('https://api.thecatapi.com/v1/images/search?breed_id=abys') .then(res => res.json()) .then(json => setImages(json)) .catch(err => console.log(err)); } , []); return ( <Fragment> <div className="App"> <h1>Image Gallery</h1> <div className="image-container"> {images.map(image => ( <Image key={image.id} image={image.url} alt={image.title} /> ))} </div> </div> </Fragment> ); }
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

No ha declarado un tipo de image en su useState

 const [images, setImages] = useState([]);

por lo que se considera como tipo never .

Lo que debe hacer es agregar una interfaz, por ejemplo, IImage y luego declararla en su useState

 export default interface IImage { id: number url: string title: string } const [images, setImages] = useState<IImage[]>([]);
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!