export type PickKeys<T> = keyof T;
export type PickValues<T> = T[PickKeys<T>];
export const NewsTypeEnum = {
Eco: 'Eco',
Quick: 'Quick',
Global: 'Global',
} as const;
export type NewsType = PickKeys<typeof NewsTypeEnum>;
type ContentRecord = {
Eco: { ecotitle: string };
Quick: { headline: string; };
Global: { title: string, price: string; };
};
type ContentByNewsType = {
[K in NewsType]: ContentRecord[K];
};
type ContentDebugByNewsType = {
[K in NewsType]: any;
};
export type NewsCardNoGeneric2 = ({
id: number;
version?: string;
logId?: string;
relatedCards?: NewsCardNoGeneric2[];
}) & (
{
newsType: "Eco";
content: ContentByNewsType["Eco"]
debugContent?: ContentDebugByNewsType["Eco"];
} | {
newsType: "Quick";
content: ContentByNewsType["Quick"]
debugContent?: ContentDebugByNewsType["Quick"];
} | {
newsType: "Global";
content: ContentByNewsType["Global"]
debugContent?: ContentDebugByNewsType["Global"];
}
)
const newsCard2: NewsCardNoGeneric2 = {
id: 2,
newsType: "Eco",
content: { ecotitle: 'ㅅ1' }
}
const newsCard3: NewsCardNoGeneric2 = {
id: 2,
newsType: "Global",
content: { price: "12", title: "t" }
}
export type NewsCard<R extends NewsType> = {
id: number;
newsType: R;
version?: string;
content?: ContentByNewsType[R];
debugContent?: ContentDebugByNewsType[R];
logId?: string;
relatedCards?: NewsCard<NewsType>[];
};
const newsCard: NewsCard<"Eco"> = {
id: 1,
newsType: "Eco",
content: { ecotitle: 'ㅅ' },
}