Reputation: 32838
I have this javascript object:
subjects = {
"1": { "id": 1, "name": "City" },
"100": { "id": 100, "name": "Test" }
};
Can someone help me by telling me how I could define this in typescript. I know I can use "any" but I would like to do this properly
Upvotes: 1
Views: 61
Reputation: 1419
If you're looking to be able to iterate over the array using a for loop, you'd need to define length as well.
Then in theory you could define it as
subjects : { id: number; name: string; }[] = <...>
If you don't want to iterate over it, then you could just define it as
subjects : { [key: string] : { id: number; name: string; } } = <...>
Upvotes: 1
Reputation: 442
subjects list:number[] = [1, 2, 3];
or
subjects list:Array<number> = [1, 2, 3];
Upvotes: 1