Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

104
Vistas
How to describe type for a generic component export in flowjs

I'm upgrading code to types-first and stuck upon need to explicitly declare type of generic react component via flowjs annotations

// @flow
import * as React from 'react';
 
type P<TArg> = {
    items: TArg[],
    onSelect: (props: TArg) => void
}

type Item = {
    key: string
}

class Autocomplete<TElem: Item> extends React.Component<P<TElem>> {

}

//its external function provided via import, i put it here for simplicity
function woodoo<F>(v: F): F {
    return v
}

If i try to export result of calling the function:

export default woodoo(Autocomplete)

I will get following error:

Cannot build a typed interface for this module. You should annotate the exports of this module with types. Cannot determine the type of this call expression. Please provide an annotation, e.g., by adding a type cast around this expression.Flow(signature-verification-failure)

If I try to export it via component:

export default (woodoo(Autocomplete): Autocomplete)

I will get following error:

Cannot use Autocomplete [1] without 1 type argument.Flow(missing-type-arg)

I know export should be more like

export default (woodoo(Autocomplete): React$ComponentType<????>)

but idk what to put in angle backets to achieve proper typing.

Making the component covariant instead of generic is not valid since the expected value passed in onSelect function is exactly the same that provided via items property and usage of covariance would not yield the same level of strictness as usage of generic would.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Have you tried this?

export default (woodoo(Autocomplete): typeof Autocomplete);

I got this answer straight up from using vscode using the quick fix feature using quick fix on vscode

about 4 years ago · Juan Pablo Isaza Denunciar

0

The easiest approach is to hover the component, check it type, and fill at the export.

Anyway you can try:

export default (woodoo(Autocomplete): React.Element<typeof Autocomplete>)

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda