I am trying to enhance the functionality of the number
type. Here is the code I attempted:
interface NumberExtension
{
IsInRange(min: number, max: number):boolean;
}
Number.prototype.IsInRange = function(min: number, max: number): boolean
{
if ((this >= min) && (this <= max)) return true;
return false;
}
I saved this in a file named extensions.ts
inside the src/app/common
directory. Is this the correct location?
However, my code is not compiling and I am getting an error message:
Property 'IsInRange' does not exist on type 'number'.
Interestingly, my editor (Visual Studio Code) is not showing any errors. What could be causing this issue? I suspect that TypeScript's number
is different from the NumberExtension
interface.