-
-
Notifications
You must be signed in to change notification settings - Fork 144
feat(generation): add support for TypeScript types generation #1897
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
base: 3.x
Are you sure you want to change the base?
Conversation
|
Would route generation a la wayfinder be something that could be included in this package? I built a very POC command for that while ago https://github.com/NeoIsRecursive/tempest-passkey-demo/blob/main/app/Generation/GenerateTypescriptRoutes.php. Super cool feature this! |
Definitely, it's something I'm planning to do as well 👍 though I don't like leaking the controller names in the front-end for some reason, and I haven't thought of an alternative. Thanks for the PoC, I'll take a look! |
Awesome! Let me know if there is anything I can help with 😄 |
One thing I like about Spatie's TypeScript transformer, and dislike about Wayfinder, is the granular control over what gets exported. Some simple DTOs are strictly for internal use and shouldn't be exposed to the frontend. If you implement automatic conversion based on heuristics, I hope there will be a way to 'opt-out' by default via config (my personal favorite) or a specific attribute (e.g., #[NoTypescript]) |
Would something strategy based make sense for configuring this? HeuresticsGenerationStrategy => opt out with an attribtue |
This pull request adds support for generating TypeScript definitions out of PHP classes and enums.
Documentation: https://github.com/tempestphp/tempest-framework/blob/feat/typescript-codegen/docs/2-features/18-typescript.md
Running the
generate:typescript-typescommand will create atypes.d.tsfile at the root of the project, with namespaced definitions:This is configurable by creating a config returning
NamespacedTypeScriptGenerationConfigorDirectoryTypeScriptGenerationConfig. The latter generates a directory structure in./typesthat's importable instead of.d.tsfiles:To mark a class for generation, it needs to have a
#[AsType]attribute. However, I plan to implement heuristics (eg. the class only has public readonly properties) to automatically convert classes without having to add an attribute.