Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript error with route().current() RouteName #808

Open
Andyuu opened this issue Jan 23, 2025 · 0 comments
Open

Typescript error with route().current() RouteName #808

Andyuu opened this issue Jan 23, 2025 · 0 comments

Comments

@Andyuu
Copy link
Contributor

Andyuu commented Jan 23, 2025

Ziggy version

v.2.5.0

Laravel version

v11.39.1

Description

Related to: 5dc7a0e

Since 2.5.0 I now get a typescript error with the below code when using strict mode: Type 'string & {}' is not assignable to type 'keyof RouteList'.

Suggested fix:

/**
 * Ziggy's Router class.
 */
interface Router {
    current(): RouteName | undefined; // Change this to ValidRouteName
    current<T extends RouteName>(name: T, params?: ParameterValue | RouteParams<T>): boolean;
    get params(): Record<string, string>;
    get routeParams(): Record<string, string>;
    get queryParams(): ParsedQs;
    has<T extends RouteName>(name: T): boolean;
}

Also I believe it would be valuable to export the ValidRouteName type definition (and perhaps some others) so it can be used for wrapper / helper code. In this situation I would be able to make a type assertion if the suggested fix is not viable for some reason.

Ziggy call and context

<Button
    href={route(route().current()!)} // Error here
>
    reload
</Button>

Ziggy configuration

//

Route definition

//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant