Reputation: 71
let colors = {
"blue" : [
{
title: "blue",
summary : "blue is ...",
image : "image of blue", // this is an optional option
link : "https:// ..."
},
{
title: "blue",
summary : "blue is ...",
link : "https:// ..."
}
],
"yellow" : [{ ... }]
}
This is an example of the structure I want to type, but I'm having trouble with it.
Upvotes: 1
Views: 22
Reputation: 20376
To take advantage of TS you will have to define a separate interface for your color property objects.
interface colorProp {
title: string;
summary : string;
image? : string;
link : string;
} ;
let colors : {
[key : string] : colorProp[]
}= {
"blue" : [
{
title: "blue",
summary : "blue is ...",
image : "image of blue", // this is an optional option
link : "https:// ..."
},
{
title: "blue",
summary : "blue is ...",
link : "https:// ..."
}
],
"yellow" : [{ ... }]
}
Upvotes: 2