繁体   English   中英

如何在类型脚本界面中定义对象

[英]How to define object in type script interface

我是Type Script的新手。 我想知道是否有一种方法可以在“ IIndex”接口中表明SystemStatus是一个具有Data和DataUrl作为属性的对象。 当前,它显示SystemStatus未定义。

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

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

    refreshSystemStatus: EmptyFunc;
}

您的代码已经声明了一个IIndex接口,该接口具有SystemStatus属性,该属性具有其自己的两个属性。 您可以像这样使用它。

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"
    } 
}

如果您在使用界面时遇到问题,则问题可能出在其他地方。 这段代码看起来不错。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM