Illegal Methods in Typescript
In javascript, we can create functions on the prototype of existing classes. Number.prototype.factorial = function() { return new Array(this.valueOf()) .fill() .reduce((acc, _, index) => acc * (index + 1), 1); }; (5).factorial(); // <- 120 However, in typescript, this is not allowed error TS2339: Property 'factorial' does not exist on type 'Number'. ► file:///C:/Users/lucas/misc/deno_test/main.ts:1:18 1 Number.prototype.factorial = function() { ~~~~~~~~~ We can add // @ts-ignore before every line and this will work, but what if we didn’t want to do that....