Skip to content
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

DataTypeScriptTransformer ignore LiteralTypeScriptType #48

Closed
mshamaseen opened this issue Sep 11, 2024 · 1 comment
Closed

DataTypeScriptTransformer ignore LiteralTypeScriptType #48

mshamaseen opened this issue Sep 11, 2024 · 1 comment

Comments

@mshamaseen
Copy link

mshamaseen commented Sep 11, 2024

✏️ Describe the bug
when DataTypeScriptTransformer is added to config/typescript-transformer.php, any LiteralTypeScriptType attribute on a collection will be ignored.

↪️ To Reproduce
See code bellow

class MyData extends Data
{
    public function __construct(
        public string $title,
        /**
         * @var Collection<int, UrlButton|CallButton>
         */
        #[WithCast(ButtonCaster::class)]
        #[LiteralTypeScriptType('Array<UrlButton|CallButton>')]
        public Collection $buttons = new Collection()
    ) {
    }
}

now run transform.

✅ Expected behavior
buttons type is expected to respect LiteralTypeScriptType and to be equal to Array<UrlButton|CallButton>
but the result is buttons: Array<UrlButton>

🖥️ Versions

Laravel: 10
Laravel Data: 4.8
PHP: 8.1

@rubenvanassche rubenvanassche transferred this issue from spatie/laravel-data Oct 4, 2024
@rubenvanassche
Copy link
Member

Mhh get your point this is because the DataTransformer for TypeScript Transformer doesn't really follow the rules and writes its own output. In TypeScript transformer 3 this all changes and then this should be possible, you'll just have to wait a few more weeks 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants