I have a structure like this:
type newsItem = {
img: string;
slug: newsSlug;
text: newsText;
};
derived from an enum like this:
export const newsEnum = {
interesting: "Interesting",
regions: "Regions",
contradictory: "Controversial",
important: "Important",
actual: "Current",
};
where
type newsSlug = keyof typeof newsEnum;
type newsText = typeof newsEnum[keyof typeof newsEnum];
I am curious, can I define the type of 'slug' as a specific key and then specify 'text' as its corresponding value in the newsEnum enum using TypeScript?
I attempted it but ran into issues:
type newsItem<T extends NewsSlug> = {
img: string;
slug: T;
text: typeof newsEnum[T];
};
This is because I plan to dynamically create an array of these items later on.