How to pass field value to referenced node template? I have content type A. It has field reference to content type B.

I'm rendering referenced node B from content type A twig template like:

{{ content.field_referenced_object }}


And that works well. 

I also render some type A filed inside it's template like:

{{ content.field_some }}


which also works.

Problem is that I need that field_some value to be displayed from referenced object B template instead of object A template, to optimize page markup. How can I pass value from content type A twig template to content type B twig template?

It twig it can be done when including template like:

{% include 'template.html' with {'foo': 'bar'} %}


But is there some analogy for Drupal 8 theming?
TL,DR: No.

Long version:

Conceptionally entity render arrays are self-contained, cachable units. The Drupal way would be either preprocessing and a custom cache context based on the referencing node, or a views block with a contextual filter.

But IMHO both ways are terrible workarounds, your Twig snippet {% include ... with ... %} is the better technique.