-
Notifications
You must be signed in to change notification settings - Fork 258
feat: generate types that match generated js #692
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
Conversation
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 |
Thinking out loud—could this be an option for the |
If the I see two types of people that would want these type definitions:
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. |
Hi! From what I can figure out, the TS user of this package is required to set up their 'ziggy-js' dependency in some way anyway (either via tsconfig, or by having a NPM module). This is written in the TS section of the docs. So, I'm not sure what is the problem of importing from 'ziggy-js' in the TS context — it should be available in one way or the other. Besides, the current generated d.ts gives glaring TS error anyway. I have tested the code suggested here, and it works fine. How about we proceed with this fix? I should point out that the import in the suggested code should probably be changed to this one:
Related: #702 |
After reviewing this again I don't think I want to add the global declaration. We can't actually be positive that users of the package have made their I'm also not clear what the Thanks a lot for the PR, I appreciate the work and the discussion! Going to close it for now but I'm definitely still open to trying to make the typing setup easier in the future. Finally, if you want the file generated exactly like this in your own project, you can set up a custom formatter for the generate command and use that instead of our built in TypeScript one. See the tests for an example and let me know if you have any questions. |
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!