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

114
Vistas
Why the use of `Function.prototype.run` inside Angular type script class is illegal

I would like to define globally new function called run inside my Angular component like so:

Function.prototype.run = function (delay: number) {
  // some content;
};

... but the compiler generates an error that the Property 'run' does not exist on type 'Function'. If I do the same code using just plain java script and compile it using node.js it compiles without any problems. Anybody knows why?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

It is generally not recommended to add properties to native JavaScript objects, but if you really want to do it, just leverage TypeScript's declaration merging:

declare global {
    interface Function {
        run: (delay: number) => void;
    }
}

Function.prototype.run = function (delay: number) {
  // some content;
};

TypeScript playground

about 4 years ago · Juan Pablo Isaza Denunciar

0

To make tsc leave you alone, just cast to any

(Function.prototype as any).run = function (delay: number) {
  // some content;
};

Or create a new type

type myType = Function & { run: Function };

(Function.prototype as myType).run = function (delay: number) {
  // some content;
};

You can also use the Object class to define new properties

Object.defineProperty(Function.prototype, 'run', {
  value: (delay: number) => {},
});
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