In my Ionic2 project, I am trying to add a new method to Number as in the following code.
interface StringConstructor {
bar(msg: string): void;
}
String.bar = function(msg: string) {
alert("Example of static extension: " + msg);
}
String.bar("Hello World");
interface NumberConstructor {
toRad(): number;
}
Number.toRad = function() { return this * (Math.PI / 180); };
export function gpsDist() {
}
When I do ionic build, it gives me the following errors:
TypeScript error: /Users/cju/Projects/Bus2-App/app/util/mathUtil.ts(7,8): Error TS2339: Property 'bar' does not exist on type 'StringConstructor'.
TypeScript error: /Users/cju/Projects/Bus2-App/app/util/mathUtil.ts(11,8): Error TS2339: Property 'bar' does not exist on type 'StringConstructor'.
TypeScript error: /Users/cju/Projects/Bus2-App/app/util/mathUtil.ts(18,8): Error TS2339: Property 'toRad' does not exist on type 'NumberConstructor'.
However the same file compiles ok outside ionic. If I compile it with tsc, I get no errors. All the code are in one file.