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

163
Views
¿Filtro de matriz en mecanografiado?

Tengo que filtrar la matriz en mecanografiado.

 const { movies, message } = useAppSelector(state => state.movies); //Here movies is array getting from backend

Aquí tengo que filtrarlo en mecanografiado.

Tengo código en javascript.

 const mathches = movies.filter(movie => { const escapeRegExp = (str) => str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&") const regex = new RegExp(escapeRegExp(search), "gi"); return movie.name.match(regex); })

No puedo entender cómo se puede definir el tipo aquí.

Aquí aparece un error cuando lo pego en el archivo ts-

 Property 'filter' does not exist on type 'never'. Parameter 'movie' implicitly has an 'any' type. Parameter 'str' implicitly has an 'any' type.

Por favor, ayúdame a definir el tipo aquí.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Puede definir un tipo para las películas:

 interface MovieType { name: string }

Luego cambie el filtro como

 const mathches = movies.filter((movie:MovieType) => { const escapeRegExp = (str: any) => str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&") const regex = new RegExp(escapeRegExp(search), "gi"); return movie.name.match(regex); })

Editar: según el cambio de pregunta

Puede actualizar las películas de la siguiente manera:

 const movies = useAppSelector<MovieType[]>(state => state.movies);
about 4 years ago · Juan Pablo Isaza Report

0

Tal vez intente usar esto

 const movies: Array<{name: string}> = [ {name: "The great wall"}, {name: "Moon Knight"}, {name: "Kong: Skull Island"}, {name: "Morbius"} ]
 const mathches = movies.filter((movie: any) => { const escapeRegExp = (str: any) => str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&") const regex = new RegExp(escapeRegExp(search), "gi"); return movie.name.match(regex); })
about 4 years ago · Juan Pablo Isaza 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!