Write a constructor for these aliases?

Did you try this out? It should recursively call itself and error.

I’m stil wondering if you need the first variadic argument args...? (I do not really use it, so there might be lack of knowledge on my side)

In the following code:

function (b::Type{<:B})(d, args...; kwargs...) 
    ft = fieldtype(b,1)
    return B(d, ft(args...; kwargs...))
end 

function (b::Type{<:B{d}})(args...; kwargs...) where d 
    ft = fieldtype(b,1)
    return B(d, ft(args...; kwargs...))
end 

b4 = B2{2}(rand(5))

I get an ambiguity since (b::Type{<:B}) is not more specific than (b::Type{<:B{d}}). And the args... allows an arbitrary amount of agruments (zero included) s.t. it cannot distinguish between (d, args...) and (args...) since args.. can just simply be empty.

However chaning args... to args works:

function (b::Type{<:B})(d, args; kwargs...) 
    ft = fieldtype(b,1)
    return B(d, ft(args; kwargs...))
end 

function (b::Type{<:B{d}})(args; kwargs...) where d 
    ft = fieldtype(b,1)
    return B(d, ft(args; kwargs...))
end 

b4 = B2{2}(rand(2))
b5 = B2(2,rand(2))
println(b4)
println(b5)

yields

B2{2, Vector{Float64}}(A2{Vector{Float64}}([0.047862735617204555, 0.38961447120103077]))
B2{2, Vector{Float64}}(A2{Vector{Float64}}([0.751595176865353, 0.4652809371308122]))

Is there a case where you need the variadic argument?

Edit: Code formatting, typo