tighten / ziggy

Use your Laravel routes in JavaScript.
MIT License
3.86k stars 247 forks source link

Generated TS file doesn't specify if a param is optional #686

Closed alexmccabe closed 3 months ago

alexmccabe commented 10 months ago

Description

The generated TS file marks all params as optional, where really only routes containing ? should be marked as optional in the generated types.

Suggestion

Line 68 of index.d.ts marks every param as optional. It looks like it should be possible to know whether a route contains a question mark during the generating process.

Alternatives

I tried some complicated extraction technique combining the generated TS file and the generated ziggy file, however that depends on the generated ziggy file being a ts file also, with the object set to as const.

bakerkretzmar commented 10 months ago

Yeah it would definitely be possible to include this info in the generated .d.ts file, I played around with it at one point.

alexmccabe commented 10 months ago

@bakerkretzmar that would be awesome, do you have any code to share? I'd be happy to open a PR if there is a base I can work from

alexmccabe commented 8 months ago

I've opened a PR for this request #697