feat(toast): add showToast overload function

This commit updates the showToast function to support multiple calling signatures, allowing for both an options object and individual parameters for style, title, and message. The latter is not officially documented, but is present in the type definitions of @raycast/api.
This commit is contained in:
ByteAtATime 2025-07-08 11:57:29 -07:00
parent e0f2889c0d
commit 3ad7c0ecbb
No known key found for this signature in database

View file

@ -97,8 +97,31 @@ class ToastImpl implements api.Toast {
}
}
export async function showToast(options: api.Toast.Options): Promise<api.Toast> {
export async function showToast(options: api.Toast.Options): Promise<api.Toast>;
export async function showToast(
style: api.Toast.Style,
title: string,
message?: string
): Promise<api.Toast>;
export async function showToast(
optionsOrStyle: api.Toast.Options | api.Toast.Style,
title?: string,
message?: string
): Promise<api.Toast> {
let options: api.Toast.Options;
if (typeof optionsOrStyle === 'object' && optionsOrStyle !== null) {
options = optionsOrStyle;
} else {
options = {
style: optionsOrStyle,
title: title as string,
message
};
}
const toast = new ToastImpl(options);
toast._sendShowCommand();
await toast.show();
return toast;
}