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

Add support for new types tag #2396

Open
drjayvee opened this issue Aug 30, 2024 · 4 comments
Open

Add support for new types tag #2396

drjayvee opened this issue Aug 30, 2024 · 4 comments
Labels

Comments

@drjayvee
Copy link

Twig has just added a new types tag which will be the official way of documenting variable types.

This can eventually replace the community convention of using {# @var #} comments.

Aside from official support and specification, comments have one major downside: they aren't added to the AST, so Twig extensions can't use them.

@Haehnchen Haehnchen added the todo label Sep 17, 2024
Haehnchen added a commit that referenced this issue Sep 17, 2024
#2396 add experimental support for extracting Twig "types" variables with types
@Haehnchen
Copy link
Owner

There is a new release with a first implementation, its allows to use types as classes and arrays.

{% types {
    foobar: '\App\Entity\ErrorReport',
    foobars: '\App\Entity\ErrorReport[]',
} %}

image

image

image

@drjayvee
Copy link
Author

@Haehnchen, I'd like to align TwigQI's support for types with the plugin's since we use both at AlisQI.

Do you have plans to add support for nullable types? Would you prefer Type|null or ?Type?

What about iterable<ValueType> and iterable<KeyType, ValueType>? Since keys can only be number / int or string, I don't think the plugin needs to do all that much with key types. But recognizing the values' type would be really useful.

Or do you prefer to align with PHPStan-style array<>, array{}, list, etc, and try to support some/many/all of the different variations? (See #1733)

I'd love to have a chat with you about this if you want.

@drjayvee
Copy link
Author

@Haehnchen I'd love to get your feedback on my previous comment.

@ruudk
Copy link
Contributor

ruudk commented Nov 20, 2024

@Haehnchen Would it be possible to make the types in {% types %} clickable too?
For example:

{% types {
    payment: 'App\Payment',
} %}

I'd like to CMD + Click on the App\Payment to navigate there.

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

No branches or pull requests

3 participants