I have read that it's possible to add Extension Methods to types in TypeScript, however having a little trouble applying this to built-in type Number.
Here's some code:
File A: NumberExtensions.ts
// tslint:disable-next-line:class-name interface-name
export interface Number {
isBigNumber(value: number): boolean;
}
// @ts-ignore
Number.prototype.isBigNumber = (value: number) => {
return value > 100000;
};
File B: Uses the above
import { Number } from "./NumberExtensions";
foo() {
const aBigNumber: number = 1000000000;
// Errors here TS2339: Property 'isBigNumber' does not exist on type 'number'.
if (aBigNumber.isBigNumber()) {
console.log("It's a big number!");
}
}
Is my declaration and usage of TypeScript extension methods correct?