From 3f008f4d82e4d978a4daae7f1c0753c6e5e78029 Mon Sep 17 00:00:00 2001 From: pmakode-akamai Date: Mon, 2 Sep 2024 13:09:03 +0530 Subject: [PATCH] Update types and comments --- packages/manager/src/features/Events/asyncToasts.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/manager/src/features/Events/asyncToasts.tsx b/packages/manager/src/features/Events/asyncToasts.tsx index ffb1452fd7d..4fbbfedf255 100644 --- a/packages/manager/src/features/Events/asyncToasts.tsx +++ b/packages/manager/src/features/Events/asyncToasts.tsx @@ -4,7 +4,8 @@ import type { Event, EventAction } from '@linode/api-v4'; interface ToastMessage { /** - * If true, the toast will be displayed with an error variant. + * If true, the toast will be displayed with an error variant for success messages \ + * or a success variant for error messages. */ invertVariant?: boolean; message: ((event: Event) => JSX.Element | null | string | undefined) | string; @@ -25,11 +26,18 @@ interface ToastOption { persist?: boolean; } -interface ToastOptions { +interface ToastOptionsBase { failure?: ToastOption | boolean; success?: ToastOption | boolean; } +/** + * To ensure that at least one of failure or success is provided while keeping both optional. + */ +type ToastOptions = + | (ToastOptionsBase & { failure: ToastOption | boolean }) + | (ToastOptionsBase & { success: ToastOption | boolean }); + const createToast = (options: ToastOptions) => { const toastConfig: Toast = {};