# Parametric type with a constrained NamedTuple

**URL:** <https://discourse.julialang.org/t/parametric-type-with-a-constrained-namedtuple/34511>\
**Category:** General Usage\
**Tags:** question, parametric-types, namedtuple\
**Created:** [February 12, 2020, 10:20am UTC](https://discourse.julialang.org/t/parametric-type-with-a-constrained-namedtuple/34511 "2020-02-12T10:20:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [February 12, 2020, 10:20am UTC](https://discourse.julialang.org/t/parametric-type-with-a-constrained-namedtuple/34511/1 "2020-02-12T10:20:57Z")

</div>

I would like to define a parametric type that constrains a `NamedTuple` to have values of a certain type, but I am running into a problem. I am not sure if it is a bug, and if there is a workaround (other than specifying the length as a type parameter).

MWE:

```julia
julia> struct ExampleType{N, T, S <: NamedTuple{N,Tuple{Vararg{T}}}}
       x::T
       y::S
       end

julia> ExampleType{(:a,:b),Float64}
ERROR: NamedTuple names and field types must have matching lengths
Stacktrace:
 [1] top-level scope at REPL[69]:1

julia> VERSION
v"1.4.0-rc1.0"

```

---

<div class="post-metadata">

**Author:** ![jbrea](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbrea/32/3879_2.png) [@jbrea](https://discourse.julialang.org/u/jbrea)\
**Post date:** [February 12, 2020, 11:12am UTC](https://discourse.julialang.org/t/parametric-type-with-a-constrained-namedtuple/34511/2 "2020-02-12T11:12:37Z")

</div>

> [@Tamas\_Papp](#):
>
> struct ExampleType{N, T, S \<: NamedTuple{N,Tuple{Vararg{T}}}}

Does `struct ExampleType{N, T, S <: NamedTuple{N,<:Tuple{Vararg{T}}}}` work?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [February 12, 2020, 11:15am UTC](https://discourse.julialang.org/t/parametric-type-with-a-constrained-namedtuple/34511/3 "2020-02-12T11:15:07Z")

</div>

Yes, it does, thanks!

I overlooked the fact that `NamedTuple` isn’t a builtin, but a parametric type like any other (in a sense).
