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

Add ability to strictly type check route names #787

Merged
merged 1 commit into from
Nov 9, 2024

Conversation

bakerkretzmar
Copy link
Collaborator

This PR adds the ability for Ziggy to display type errors when passed route names that aren't present in the route list:

declare module 'ziggy-js' {
    interface RouteList {
        'home': [];
    }
    // New in this PR
    interface TypeConfig {
        strictRouteNames: true;
    }
}

route('hom'); // TypeError because there's no route called "hom"

As seen above, this functionality can be enabled by overriding the new TypeConfig interface and setting a strictRouteNames property on it to true.

This is optional and not enabled by default, although in the future we may want to consider whether this would be preferable as Ziggy's default behavior out of the box.

Thanks to @Andyuu for this solution! See #759 (comment).

@bakerkretzmar bakerkretzmar self-assigned this Nov 9, 2024
@bakerkretzmar bakerkretzmar merged commit d3d7cb0 into 2.x Nov 9, 2024
22 checks passed
@bakerkretzmar bakerkretzmar deleted the strict-route-checks branch November 9, 2024 17:03
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

Successfully merging this pull request may close these issues.

1 participant