Why do these two have different types?

using StructArrays

test1 = StructArray{NamedTuple{(:a, :b), NTuple{2, Float32}}}((a=[0f0,0f0,1f0,1f0,2f0,2f0,2f0],b=[0f0,0f0,0f0,0f0,0f0,0f0,0f0]))
7-element StructArray(::Vector{Float32}, ::Vector{Float32}) with eltype NamedTuple{(:a, :b), Tuple{Float32, Float32}}:
 (a = 0.0, b = 0.0)
 (a = 0.0, b = 0.0)
 (a = 1.0, b = 0.0)
 (a = 1.0, b = 0.0)
 (a = 2.0, b = 0.0)
 (a = 2.0, b = 0.0)
 (a = 2.0, b = 0.0)

test2 = StructArray{NamedTuple{(:a, :b), NTuple{2, Float32}}}((a=[0,0,1,1,2,2,2],b=[0,0,0,0,0,0,0]))
7-element StructArray(::Vector{Int64}, ::Vector{Int64}) with eltype NamedTuple{(:a, :b), Tuple{Float32, Float32}}:
 (a = 0.0, b = 0.0)
 (a = 0.0, b = 0.0)
 (a = 1.0, b = 0.0)
 (a = 1.0, b = 0.0)
 (a = 2.0, b = 0.0)
 (a = 2.0, b = 0.0)
 (a = 2.0, b = 0.0)

typeof(test1)
StructVector{NamedTuple{(:a, :b), Tuple{Float32, Float32}}, NamedTuple{(:a, :b), Tuple{Vector{Float32}, Vector{Float32}}}, Int64} (alias for StructArray{NamedTuple{(:a, :b), Tuple{Float32, Float32}}, 1, NamedTuple{(:a, :b), Tuple{Array{Float32, 1}, Array{Float32, 1}}}, Int64})

typeof(test2)
StructVector{NamedTuple{(:a, :b), Tuple{Float32, Float32}}, NamedTuple{(:a, :b), Tuple{Vector{Int64}, Vector{Int64}}}, Int64} (alias for StructArray{NamedTuple{(:a, :b), Tuple{Float32, Float32}}, 1, NamedTuple{(:a, :b), Tuple{Array{Int64, 1}, Array{Int64, 1}}}, Int64})

I thought that for both the element type is given explicitly, so why is the type of ttt1 and ttt2 different? That seems weird, I would either expect the elements of test2.a and test2.b to be interpreted as Float32 OR giving an error upon construction of test2. Any hints? Thanks.

It seems that StructArray stores the original data you gave it, converting as you request it. And in doing that embeds the type of the original data in its type.

julia> z = StructArray{ComplexF64}(([1, 2], [3.0, 4.0]))
2-element StructArray(::Vector{Int64}, ::Vector{Float64}) with eltype ComplexF64:
 1.0 + 3.0im
 2.0 + 4.0im

julia> z.re
2-element Vector{Int64}:
 1
 2

julia> z.im
2-element Vector{Float64}:
 3.0
 4.0

julia> z[1]
1.0 + 3.0im

julia> typeof(z)
StructVector{ComplexF64, @NamedTuple{re::Vector{Int64}, im::Vector{Float64}}, Int64} (alias for StructArray{Complex{Float64}, 1, @NamedTuple{re::Array{Int64, 1}, im::Array{Float64, 1}}, Int64})