Let's say I have in interface like this:
export interface Promotion {
title: string;
image?: string;
description?: string;
startDate?: string;
endDate?: string;
type: 'discountWithImage' | 'discount' | 'countdown';
}
Now my questions is, since I now for sure that if the key type is equal to 'countdown' then the endDate and the startDate will not be undefined. Is there a way to do it in typescript? so something like:
export interface Promotion {
title: string;
image?: string;
description?: string;
startDate?: string;
endDate: Promotion.type === 'countdown' ? string : undefined;
type: 'discountWithImage' | 'discount' | 'countdown';
}
example to explain on playground Playground