Skip to content

Instantly share code, notes, and snippets.

@soxjke
Last active March 31, 2021 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soxjke/35a8047eebc142dd1a390099d78406a0 to your computer and use it in GitHub Desktop.
Save soxjke/35a8047eebc142dd1a390099d78406a0 to your computer and use it in GitHub Desktop.
Discriminated union
import { DestinationType, IBoxData, IWifiData, IWifiTypeData, SocialMediaItem } from '../../types/config/destination';
export interface BaseDestinationConfigg {
readonly type: DestinationType;
readonly id: string;
readonly title: string;
readonly tooltip: string;
}
interface CallDestinationConfigg extends BaseDestinationConfigg {
readonly type: DestinationType.Call;
readonly boxDescription: string;
readonly placeholder: string;
}
interface EmailDestinationConfigg extends BaseDestinationConfigg {
readonly type: DestinationType.Email;
readonly emailAddress: IBoxData;
readonly subject: IBoxData;
readonly message: IBoxData;
}
interface SocialMediaDestinationConfigg extends BaseDestinationConfigg {
readonly type: DestinationType.SocialMedia;
readonly boxDescription: string;
readonly placeholder: string;
}
interface SocialMediaListDestinationConfigg extends BaseDestinationConfigg {
readonly type: DestinationType.SocialMediaList;
readonly socialList: SocialMediaItem[];
}
interface TextMessageDestinationConfigg extends BaseDestinationConfigg {
readonly type: DestinationType.TextMessage;
readonly phoneNumber: IBoxData;
readonly message: IBoxData;
}
interface UploadFileDestinationConfigg extends BaseDestinationConfigg {
readonly type: DestinationType.UploadFile;
readonly boxDescription: string;
readonly placeholder: string;
}
interface UrlDestinationConfigg extends BaseDestinationConfigg {
readonly type: DestinationType.Url;
readonly boxDescription: string;
readonly placeholder: string;
}
interface VenmoDestinationConfigg extends BaseDestinationConfigg {
readonly type: DestinationType.Venmo;
readonly userName: IBoxData;
readonly value: IBoxData;
readonly note: IBoxData;
}
interface WifiDestinationConfigg extends BaseDestinationConfigg {
readonly type: DestinationType.Wifi;
readonly ssid: IWifiData;
readonly password: IBoxData;
readonly wifiTypes: IWifiTypeData[];
readonly hiddenNetworkAvailable: boolean;
}
type DestinationConfig = CallDestinationConfigg | EmailDestinationConfigg | SocialMediaDestinationConfigg |
SocialMediaListDestinationConfigg | TextMessageDestinationConfigg | UploadFileDestinationConfigg |
UrlDestinationConfigg | VenmoDestinationConfigg | WifiDestinationConfigg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment