I'm interested in things like this as well. Can you provide an example of what you're thinking of? Something like JSX? Other data structures that are transformed into HTML by a library? The latter seems to be counter to your argument about requiring the use of some framework or library, but I can't think of any alternatives off the top of my head.
But with XML as a native data structure you can do things like typehint a tag:
public function setTitle(:document:base $base, string $title): void
{
$base->setAttribute("pagetitle", $title);
}
[0]https://pastebin.com/m54VDwNY