Skip to content

[Bug]: Not compatible with Eloquence\Behaviours\HasCamelCasing #91

@PerryRylance

Description

@PerryRylance

What happened?

When I install and use kirkbushell/eloquence's HasCamelCasing, this library still generates snake case TypeScript interfaces.

Because the models are serialized with camel case attributes, my interfaces don't reflect how the model actually looks and I either end up with failing type checks or runtime errors due to wrong field names.

I appreciate if first party support for integration isn't desirable - Would you be open to adding a setting for typescriptable.eloquent.printer_class then changing EloquentType.php:38 from

$type->typescript = PrinterEloquentTypescript::make($type->app()->models());

to

$type->typescript = ($type->config()->printerClass)::make($type->app()->models());

This will allow me to subclass \Kiwilan\Typescriptable\Typed\Eloquent\Printer\PrinterEloquentTypescript and hook in with my own printer where I can transform attribute names to camel case :) (Tested locally and working)

I'm unable to open a pull request, happy to fork, I'd prefer to contribute rather than fork if possible.

How to reproduce the bug

  • Install this package
  • Install kirbushell/eloquence
  • Make a model with some snake case fields in the DB
  • Use the HasCamelCasing trait on one of your models
  • Run artisan typescriptable
  • Observe that the generated interfaces have the snake case names

Package Version

3.1.05

PHP Version

8.4

Which operating systems does with happen with?

Linux

Notes

No response

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions