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

113
Views
El tipo genérico 'FlatListProps<ItemT>' requiere 1 tipo de argumento(s)

Tengo un componente de artículo al que paso un ListHeaderComponent que es un accesorio de FlatListProps como este:

 <Article
 article={article}
 ListHeaderComponent={<HomeBackgroundImage />}
/>

En Article.tsx he establecido el siguiente tipo:

 type Props = {
 article: ArticleType;
} & Omit<FlatListProps, 'data' | 'renderItem' | 'showsVerticalScrollIndicator'>;

Sin embargo, me sale el siguiente error:

 Generic type 'FlatListProps<ItemT>' requires 1 type argument(s).

Pero no estoy muy seguro de qué se supone que debo pasar como argumento.

 type Props = {
 article: ArticleType;
} & Omit<FlatListProps<any>, 'data' | 'renderItem' | 'showsVerticalScrollIndicator'>;

Esto elimina el error, sin embargo, empiezo a recibir el error de que el elemento tiene explícitamente cualquier tipo en FlatList:

 const Article: FunctionComponent<Props> = ({ article, ...rest }) => {
 return (
 <FlatList
 data={article.sections}
 renderItem={({ item: section, index }) => {
 const firstCard = section.items.find((item) => {
 return item.contentType !== 'heading' && item.contentType !== 'body';
 });
 const indexOfFirstCard = section.items.indexOf(firstCard!);
 const sectionType = firstCard?.contentType;

 return (
 <Section isFirst={index === 0} sectionType={sectionType}>
 {section.items.map((item, idx) => (
 <Item key={idx} item={item} itemIndex={idx} indexOfFirstCard={indexOfFirstCard} />
 ))}
 </Section>
 );
 }}
 showsVerticalScrollIndicator={false}
 {...rest}
 />
 );
};
almost 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Al observar el código nativo de reacción para FlatList , parece que ItemT en FlatListProps<ItemT> es el tipo del elemento en la matriz de data . Entonces, en su caso, sería el tipo de un elemento article.sections , que se puede escribir como ArticleType['sections'][number] .

almost 4 years ago · Santiago Trujillo 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!