From 3b48a375b0b819a50e73f088fce0cf38aa3dcd66 Mon Sep 17 00:00:00 2001 From: abdmmar Date: Tue, 28 Dec 2021 01:49:52 +0700 Subject: [PATCH] fix types --- src/toast.d.ts | 54 +++++--------------------------------------------- src/toast.js | 22 ++++++++------------ 2 files changed, 13 insertions(+), 63 deletions(-) diff --git a/src/toast.d.ts b/src/toast.d.ts index 7473af4..fea48dc 100644 --- a/src/toast.d.ts +++ b/src/toast.d.ts @@ -42,54 +42,9 @@ export type ToastOptions = { */ declare function toast(message: string, options?: ToastOptions): string; declare namespace toast { - function loading(message: any, options?: { - icon: { - type: string; - content: string; - }; - duration: string; - closeable: boolean; - theme: { - type: string; - style: { - background: string; - color: string; - stroke: string; - }; - }; - }): any; - function success(message: any, options?: { - icon: { - type: string; - content: string; - }; - duration: string; - closeable: boolean; - theme: { - type: string; - style: { - background: string; - color: string; - stroke: string; - }; - }; - }): any; - function error(message: any, options?: { - icon: { - type: string; - content: string; - }; - duration: string; - closeable: boolean; - theme: { - type: string; - style: { - background: string; - color: string; - stroke: string; - }; - }; - }): any; + function loading(message: string, options?: ToastOptions): string; + function success(message: string, options?: ToastOptions): string; + function error(message: string, options?: ToastOptions): string; /** * Dismiss toast by id * @param {string} id @@ -103,13 +58,14 @@ declare namespace toast { /** * Automatically add loading toast, success or error toast in promise * @param {Promise} promise + * @param {object} message * @param {string} message.loading * @param {string} message.success * @param {string} message.error * @param {ToastOptions} [options] * @returns {Promise} */ - function promise(promise: Promise, message?: { + function promise(promise: Promise, message: { loading: string; success: string; error: string; diff --git a/src/toast.js b/src/toast.js index 994df1d..0eab9ba 100644 --- a/src/toast.js +++ b/src/toast.js @@ -79,15 +79,12 @@ function createToastCloseButton(toastItem) { * @param {'blank' | 'success' | 'loading' | 'error' | 'custom'} type */ function createHandler(type) { - return function ( - message, - options = { - icon: { type: '', content: '' }, - duration: '', - closeable: false, - theme: { type: 'light', style: { background: '', color: '', stroke: '' } } - } - ) { + /** + * @param {string} message + * @param {ToastOptions} [options] + * @returns {string} + */ + return function (message, options) { const toast = createToast(message, type, options); return toast.id; }; @@ -152,17 +149,14 @@ toast.dismiss = function (toastId) { /** * Automatically add loading toast, success or error toast in promise * @param {Promise} promise + * @param {object} message * @param {string} message.loading * @param {string} message.success * @param {string} message.error * @param {ToastOptions} [options] * @returns {Promise} */ -toast.promise = async function ( - promise, - message = { loading: '', success: '', error: '' }, - options -) { +toast.promise = async function (promise, message, options) { const id = toast.loading(message.loading, { ...options }); try {