私のIonic2プロジェクトで、次のコードでNumberに新しいメソッドを追加しようとしています。私はイオン性のビルドを行うとionic2 typescript StringまたはNumberにメソッドを追加する際のコンパイルエラー
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() {
}
は、それは私に次のエラーを与える:同じファイルがOK外のイオンをコンパイルしかし
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'.
。私がtscでコンパイルすると、エラーは発生しません。すべてのコードは1つのファイルにあります。
私は「ノードtsc.js myfile.ts」と「ノードtypescriptですを行うことによって、「イオンビルド」コマンドの外のファイルをコンパイルしようとしたが.js myfile.ts "、どちらもエラーなしでコンパイルします。 tsc.jsとtypescript.jsはionic-gulp-browserify-typescript/node_modules/tsify/node_modules/typescript/libにあります。 –