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

107
Visualizações
How do I extend a base interface dynamically?

I am using react-query and have a lot of useQuery hooks that accept these parameters:

export interface UseQueryHookProps<K> {
  client: K;
  isEnabled?: boolean;
}

How would I write the interface to be more generic to accept any or rather unknown additional interface/s?

So something like this:

export interface UseQueryHookProps<K, T> extends T {
  client: K;
  isEnabled?: boolean;
}

Where UseQueryHookProps would be called:

export const useGetJob = ({
  client: monitoringService,
  isEnabled = true,
  jobId,
}: UseQueryHookProps<MonitoringServiceClient, {jobId: string}>) 

I am not sure how to write this?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You are not allowed to extend interface with T. In order to do that - T should be statically known.

If you want to extend UseQueryHookProps with T you should use type syntax instead of interface.

export interface UseQueryHookProps<K> {
  client: K;
  isEnabled?: boolean;
}

type ExtendHookProps<K, T> = UseQueryHookProps<K> & T

interface MonitoringServiceClient {
  tag: 'MonitoringServiceClient'
}

export const useGetJob = ({
  client: monitoringService,
  isEnabled = true,
  jobId,
}: ExtendHookProps<MonitoringServiceClient, { jobId: string }>) => {

}

Playground

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