Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

112
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!