inertiajs / inertia

Inertia.js lets you quickly build modern single-page React, Vue and Svelte apps using classic server-side routing and controllers.
https://inertiajs.com
MIT License
6.56k stars 435 forks source link

Incorrect types for `use:inertia` action #2001

Closed jrmajor closed 1 month ago

jrmajor commented 1 month ago

Version:

Describe the problem:

Types for @inertiajs/svelte indicate that use:inertia must receive additional arguments, even though it doesn't need them.

[...]/resources/js/Components/Pagination/PaginationLink.svelte:26:7
Error: Expected 2 arguments, but got 1. (ts)
    <a
        use:inertia
        href={url}

Looks like it may be fixed by 69292ef3592ccca5e0f05f7ce131a53f6c1ba22b, but I'm not sure.

Steps to reproduce:

Use use:inertia action without any arguments and run TypeScript.

jrmajor commented 1 month ago

Before types were added to Svelte adapter, I used the following signature:

export const inertia: Action<
    HTMLAnchorElement | HTMLButtonElement,
    (VisitOptions & { href?: string }) | undefined
>;
pedroborges commented 1 month ago

Thanks for reporting this @jrmajor! I can confirm that commit 69292ef fixes the type error you ran into. Here's the new signature:

inertia(node: ActionElement, options?: ActionParameters): ActionReturn<ActionParameters, ActionAttributes>

While looking into this type error, I noticed the custom events needed some adjustment so I opened #2003.