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

357
Visualizações
TypeScript error when setting a component's state: Argument of type 'X' is not assignable to parameter of type '() => void'

I am having a TypeScript error when calling setState: enter image description here

That's what I am actually doing:

  updateRequests(requests: any, cb:Function|null = null) {
    this.setState(
      {
        requests: {
          ...this.state.requests,
          items: requests,
          loading: false,
        },
      },
      () => {
        if (cb) cb();
      }
    );

Here's a Component state:

export interface IServersScreenState {
  requests: {
    items: [];
    loading: boolean;
    statuses: {};
    page: number;
    lastPage: number;
    scrollLoading: boolean;
  };
}

Don't actually understand why it's happening like that, because I don't have any declaration in the state, that requests needs to be look like ()=>void

here's my setState:

  setState<T>(...args: T[]) {
    if (this.__mounted__) {
      //@ts-expect-error spread error
      super.setState(...args) as $TSFixMe;
    }
  }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You've defined setState to accept a generic, and then aren't filling in the generic when it's called. Try replacing

this.setState(

with

this.setState<IServersScreenState>(

That should get you closer to following the type you've set up.

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