简体   繁体   English

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

[英]How to define object in type script interface

I am very new to Type Script. 我是Type Script的新手。 I am wondering whether there is a way to tell that in the interface "IIndex" SystemStatus is an object that has Data and DataUrl as properties. 我想知道是否有一种方法可以在“ IIndex”接口中表明SystemStatus是一个具有Data和DataUrl作为属性的对象。 Currently it is showing that the SystemStatus is undefined. 当前,它显示SystemStatus未定义。

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

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

    refreshSystemStatus: EmptyFunc;
}

Your code is already declaring an IIndex interface that has a SystemStatus property having two properties of its own. 您的代码已经声明了一个IIndex接口,该接口具有SystemStatus属性,该属性具有其自己的两个属性。 You can use it like this. 您可以像这样使用它。

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

If you're having problems using your interface, the problem is somewhere else. 如果您在使用界面时遇到问题,则问题可能出在其他地方。 This code looks fine. 这段代码看起来不错。

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

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