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

108
Vistas
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 Respuestas
Responde la pregunta

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 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