Twig type hint support for intersection and union types
Hi. Can you help me to figure out how to type hint intersection(union) types in twig templates?
For a single interface, I can do something like this and it works fine:
{# @var f1 \App\Foo #}
But how can I type hint intersections? These don't work.
{#@var f1 (\App\Foo|\App\Bar) #}
{#@var f2 (\App\Foo&\App\Bar) #}
Thank you!
请先登录再写评论。
Hi Roman,
According to this ticket, var typehints are yet to be supported out-of-box:
https://youtrack.jetbrains.com/issue/WI-39752/Add-var-type-hinting-support-for-twig
I assume that you have a Symfony Support plugin installed, right?
If this is the case, it seems to be, it does not support union types at this moment:
https://github.com/Haehnchen/idea-php-symfony2-plugin/issues/1327
Yes, both Symfony and Twig plugins are enabled. Sadly, the Twig plugin doesn't support intersections and DNF types that are supported by PHP 8.1 and 8.2 :(
I am also having the same issue right now, and tried a couple of things like:
```
{# @var \App\Foo | \App\Bar f1 #}
```
But then the union is not even counted as a type anymore, as I cannot navigate to its definition now.