An opinionated toast component for React.
Infer the promise data in toast promise (#81)
João Pedro Magalhães3c7503a8c426
diff --git a/src/state.ts b/src/state.tsindex 75c8e0e..69ac95f 100644--- a/src/state.ts+++ b/src/state.ts@@ -73,7 +73,7 @@ class Observer {return this.create({ ...data, type: 'success', message });};- promise = (promise: PromiseT, data?: PromiseData) => {+ promise = <ToastData>(promise: PromiseT<ToastData>, data?: PromiseData<ToastData>) => {return this.create({ ...data, promise });};diff --git a/src/types.ts b/src/types.tsindex dbe3392..fafad2a 100644--- a/src/types.ts+++ b/src/types.ts@@ -2,11 +2,11 @@ import React from 'react';export type ToastTypes = 'normal' | 'action' | 'success' | 'error' | 'loading';-export type PromiseT = Promise<any> | (() => Promise<any>);+export type PromiseT<Data = any> = Promise<Data> | (() => Promise<Data>);-export type PromiseData = ExternalToast & {+export type PromiseData<ToastData = any> = ExternalToast & {loading: string | React.ReactNode;- success: string | React.ReactNode | ((data: any) => React.ReactNode | string);+ success: string | React.ReactNode | ((data: ToastData) => React.ReactNode | string);error: string | React.ReactNode | ((error: any) => React.ReactNode | string);};diff --git a/website/src/components/Types/Types.tsx b/website/src/components/Types/Types.tsxindex 9e281b5..7cd7236 100644--- a/website/src/components/Types/Types.tsx+++ b/website/src/components/Types/Types.tsx@@ -85,7 +85,7 @@ toast.promise(promise, {error: 'Error',});`,action: () =>- toast.promise(+ toast.promise<{ name: string }>(() =>new Promise((resolve) => {setTimeout(() => {