kbrgl / svelte-french-toast

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

TypeScript error when using a function in toast.promise() #35

Closed khromov closed 1 year ago

khromov commented 1 year ago

I have some code that looks like this:

toast.promise(response, {
    loading: 'Saving...',
    success: 'Saved!',
    error: (e) => `Something went wrong: ${e}`
});

The code works, however I get the TS error:

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

I tried typing this in various ways, but I can't figure out how to get it to work. For example both of these examples do not work either:

// Type '(e: any) => Renderable' is not assignable to type 'Renderable'.ts(2322)

// Ex 1
error: (e: any): Renderable => `Something went wrong: ${e}`

// Ex 2
error: (e: any) => {
    return `Something went wrong: ${e}` as Renderable;
}
khromov commented 1 year ago

I see now that the types seem to differ between my local environment and on GitHub. On GitHub the types are:

error: ValueOrFunction<Renderable, any>;

As per here.

But in my local project, the types look like this:

 promise<T>(promise: Promise<T>, msgs: {
        loading: Renderable;
        success: Renderable;
        error: Renderable;
    }, opts?: DefaultToastOptions | undefined): Promise<T>;

So it makes sense that it wouldn't work. Perhaps the Types need to be updated in the NPM version?

khromov commented 1 year ago

Looks like this was fixed in the 1.0.4 beta but because of the beta status my NPM wasn't picking up the new version. If you have the same issue you can run npm i svelte-french-toast@1.0.4-beta.0 --save and it should fix the types.

kbrgl commented 1 year ago

@khromov Thanks a lot for flagging and resolving the issue! Let me know if the beta version's working for you. I'll promote it to stable soon.