I have a question about extracting the type of a nested object with similar structures. The object in question contains multiple sub-objects that all follow the same pattern.
const VALUES = {
currentStreak: {
display: "Current streak",
value: currentStreak,
},
longestStreak: {
display: "Longest streak",
value: longestStreak,
},
contributionsThisYear: {
display: "Contributions this year",
value: contributionsThisYear,
},
totalContributions: {
display: "Total contributions",
value: totalContributions,
},
currentCompany: {
display: "Working at",
value: currentCompany,
},
}
The main keys of the object are working fine, but I'm looking to define types for the individual keys within each object as well.
export type Something = {
[key in keyof typeof VALUES]: { [key: string]: string | number };
};
How can I properly define the types for each object so that they contain both display
and value
, where value
can be either a string or a number?
Apologies if this is repetitive! I just want to get a clear understanding once and for all.