Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

98
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda