kbrgl / svelte-french-toast

🍞🥂 Buttery smooth toast notifications for Svelte
https://svelte-french-toast.vercel.app/
MIT License
838 stars 30 forks source link

Incorporate promise results into toast #5

Closed blazzjosh closed 2 years ago

blazzjosh commented 2 years ago

Can i provide a function to the success/error messages to incorporate the result/error of the promise?

toast.promise(
  myPromise,
  {
    loading: 'Loading',
    success: (data) => `Successfully saved ${data.name}`,
    error: (err) => `This just happened: ${err.toString()}`,
  }
)
kbrgl commented 2 years ago

Yes, you can. The example you provided will work out of the box. Here’s a REPL to demonstrate:

https://svelte.dev/repl/24dd3ad1df394a9d8bc6333a2e7a19d3?version=3.48.0

shiftlabs1 commented 1 year ago

@kbrgl did something change since then . In a sveltekit (typescript) project. I get the error

Type '(data: any) => string' is not assignable to type 'Renderable'.

where Renderable is defined as

export declare type Renderable = typeof SvelteComponent | string | null;

as per the code . So

(args:any) => string 

is not covered by the Renderable type ?? Sorry i had to add this to a closed issue.

shiftlabs1 commented 1 year ago

if i do this however

const customMessage = (arg: any): string => { }
export declare type Renderable = typeof SvelteComponent | typeof customMessage | string | null;

The error goes away .havent tested though. will test now and maybe do a PR if that is fine by you