This is a more refined version (from ConstructionBase.jl) which completely avoids Julia internals:
@generated function constructorof(::Type{T}) where T
getfield(parentmodule(T), nameof(T))
end
I think ultimately the issue is that, for diagonal types like f(x::A)::A where A, when f is called the type variable A will be concrete and fully parameterized; before you can change some parameters, you first need to shed some by climbing up to a non-concrete UnionAll type.
Without this type annotation/conversion, f’s output type is being correctly inferred on my machine. I don’t think there’s any need for concern one way or the other, but are you sure this is the point in your codebase where type stability is being lost?