# Behavior of \`fieldtypes\` applied to \`Tuple{...}\`

**URL:** <https://discourse.julialang.org/t/behavior-of-fieldtypes-applied-to-tuple/110030>\
**Category:** General Usage\
**Tags:** question, type, tuple\
**Created:** [February 10, 2024, 3:00pm UTC](https://discourse.julialang.org/t/behavior-of-fieldtypes-applied-to-tuple/110030 "2024-02-10T15:00:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![CameronBieganek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cameronbieganek/32/6915_2.png) [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Post date:** [February 10, 2024, 3:00pm UTC](https://discourse.julialang.org/t/behavior-of-fieldtypes-applied-to-tuple/110030/1 "2024-02-10T15:00:12Z")

</div>

Here is the docstring for `fieldtypes`:

```julia
fieldtypes(T::Type)

The declared types of all fields in a composite DataType T as a tuple.

Examples
≡≡≡≡≡≡≡≡≡≡

julia> struct Foo
           x::Int64
           y::String
       end
  
julia> fieldtypes(Foo)
(Int64, String)

```

As far as I can tell, this only seems to address composite types defined with the `struct` keyword. However, it so happens that `fieldtypes` performs a useful operation on a `Tuple{...}` type:

```julia
julia> fieldtypes(Tuple{Int, String})
(Int64, String)

```

It doesn’t seem like this behavior is really covered by the current docstring. So, my question is, is the behavior of `fieldtypes` when applied to a `Tuple{...}` type considered public API that we can rely on?

---

<div class="post-metadata">

**Author:** ![CameronBieganek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cameronbieganek/32/6915_2.png) [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Post date:** [February 10, 2024, 3:23pm UTC](https://discourse.julialang.org/t/behavior-of-fieldtypes-applied-to-tuple/110030/2 "2024-02-10T15:23:43Z")

</div>

There are a few related unit tests in [test/reflection.jl](https://github.com/JuliaLang/julia/blob/master/test/reflection.jl), like these:

```julia
@test fieldtype(Tuple{Vararg{Int8}}, 1) === Int8
@test fieldtype(Tuple{Vararg{Int8}}, 10) === Int8

@test fieldtype((NamedTuple{T,Tuple{Int,String}} where T), 1) === Int
@test fieldtype((NamedTuple{T,Tuple{Int,String}} where T), 2) === String

@test fieldtypes((NamedTuple{T,Tuple{Int,String}} where T)) === (Int, String)

```

So, that provides some hope. But there are no unit tests for the simple tuple type case like `fieldtypes(Tuple{Int, String})`.

---

<div class="post-metadata">

**Author:** ![matthias314](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@matthias314](https://discourse.julialang.org/u/matthias314)\
**Post date:** [February 10, 2024, 6:42pm UTC](https://discourse.julialang.org/t/behavior-of-fieldtypes-applied-to-tuple/110030/3 "2024-02-10T18:42:50Z")

</div>

Besides `fieldtypes`, the functions `fieldtype` and `Base.datatype_nfields` also work for `Tuple`. It would be great to see this reflected in the documentation.
