Open rrmesquita opened 11 months ago
Very interested in making this work but need to think it through some more. We can't always count on being able to import from ziggy-js
(see #680).
Thinking out loud—could this be an option for the ziggy:generate
command? Like we include this declaration by default but add something like --no-declare
to let people omit it if they need to?
If the --no-declare
option is passed, it outputs the same as it does now, right? That could work I guess, but...
I see two types of people that would want these type definitions:
route
helper injected by the @routes
directive.How problematic it would be to just require the user to install the npm package – which is super lightweight – at least as a dev dependency? If you think about, it makes sense, it fixes the issue, and it saves us from having to implement a not so elegant solution.
Let me know your thought and if there's another use-case I'm missing.
Definitely not going to require installing the npm package, the goal is for almost everyone to never need it.
Right now, the README already asks the user to add a piece of typing in a
.d.ts
file in order to make the IDE aware of the globalroute
function. Since this function is global and always available, I don't see a reason to leave that step to the user.Another problem that this PR solves, is the error message shown when you want to import the Ziggy config from the generated JS file into a TS file.
I'll keep this as a draft for now, as this change would also require changes to tests and the README. Let me know your thoughts, and thanks for creating this awesome lib that helps me a lot!