简体   繁体   中英

How to define object in type script interface

I am very new to 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. Currently it is showing that the SystemStatus is undefined.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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