2016-05-24 15 views
0

私は非常にタイプスクリプトです。私はインターフェイス "IIndex" SystemStatusがプロパティとしてDataとDataUrlを持つオブジェクトであることを伝える方法があるかどうか疑問に思っています。現在、SystemStatusが未定義であることを示しています。タイプスクリプトインターフェイスでオブジェクトを定義する方法

interface IIndex extends ng.IScope { 
    TotalRequestedJobCount: number; 
    TotalScheduledJobCount: number; 

    SystemStatus: { 
     Data: any; 
     DataUrl: string; 
    } 

    refreshSystemStatus: EmptyFunc; 
} 

答えて

0

あなたのコードはすでに、独自の2つのプロパティを持つSystemStatus性質を持っているIIndexインタフェースを宣言しています。このように使うことができます。

type EmptyFunc = any; 

module ng { 
    export interface IScope { } 
} 

interface IIndex extends ng.IScope{ 
    TotalRequestedJobCount: number; 
    TotalScheduledJobCount: number; 

    SystemStatus:{ 
     Data: any; 
     DataUrl: string; 
    } 
    refreshSystemStatus: EmptyFunc; 
} 


var obj: IIndex = { 
    TotalRequestedJobCount: 1, 
    TotalScheduledJobCount: 2, 
    refreshSystemStatus: "foo", 
    SystemStatus: { 
     Data: 1337, 
     DataUrl: "asdf" 
    } 
} 

あなたのインターフェイスを使用して問題がある場合、問題がどこかにあります。このコードは上手く見えます。

関連する問題