2016-07-19 5 views
2

次のコードは "test-file.js"ファイルにあり、 "test-file.d.ts"ファイルに移植してそれを私の "test1.ts"にインポートし、TypescriptのJavaScript "Types"に対してコード化することができます。タイプスクリプト宣言ファイルでシングルトンのjavascriptクラスを定義する方法

"test-file.d.ts"でTypescriptから同じ実装が存在するように以下を定義する方法を見つけ出すことができませんでした。

(function(application) { 

application.Message = function() { 

    this.m_messageContents = "New Message"; 

}; 

application.Message.prototype.getApplicationMessageContents = function() { 
    return this.m_messageContents; 
}; 

application.SystemFactory = (function(){ 

var factory = 
    /** 
    * @lends application.SystemFactory 
    */ 
    { 
     createMessage: function() { 
      return application.Message(); 
     } 
    }; 
    return factory; 

}()); 

}(application)); 

私は私が私の「test1.ts」にインポートしたい上記で述べた代わりとして、* .TSファイルにこのファイルを再コーディングする必要はありません。

ありがとうございました。

答えて

0

これはあなたにOKであれば、私は見てみましょう:

declare module application { 
    export class Message { 
     getApplicationMessageContents(): string; 
    } 

    export class SystemFactory { 
     static createMessage(): Message; 
    } 
} 

そして、あなたはこのように使用することができます:あなたが見ることができるように、あなたは static createMessage(): Message;として、静的ではなくを宣言します

let message = application.SystemFactory.createMessage(); 
let content = message.getApplicationMessageContents(); 

クラス。

+0

これは近いですが、このようにする必要があります。let message = application.SystemFactory.createMessage(); let = message.getApplicationMessageContents();コードはこのように見える必要があります...(これは明らかに機能しません)モジュールアプリケーションの宣言{ export class Message { getApplicationMessageContents():string; } エクスポートstatic class SystemFactory { createMessage():メッセージ; } } – Daz

+0

私は間違っています...私は答えを更新します – Diullei

+0

ありがとう、ディウリー。 – Daz

関連する問題