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

209
Vistas
Override built-in method in Typescript and delete the old method?

I know I can use declaration merging to add a new definition to built-in methods like this:

interface ObjectConstructor {
  keys<T>(o: T & (T extends any[] ? never : object): string[];
}

I want this definition of Object.keys to disallow arrays. However, this adds a new overloaded definition to Object.keys, it doesn't remove the existing definitions. If I call Object.keys({}), it uses my new definition. If I call Object.keys([]), it skips my definition and uses the built-in definition.

Is there a way to delete the old definitions of Object.keys?

Edit: for this particular problem, I realized I could just do keys(o: any[]): never. However, it'll be useful to know a general solution.

about 4 years ago · Juan Pablo Isaza
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