# Difference between Type.parameters and Type.types

**URL:** <https://discourse.julialang.org/t/difference-between-type-parameters-and-type-types/95622>\
**Category:** General Usage\
**Created:** [March 6, 2023, 4:03pm UTC](https://discourse.julialang.org/t/difference-between-type-parameters-and-type-types/95622 "2023-03-06T16:03:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![wsshin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wsshin/32/360_2.png) [@wsshin](https://discourse.julialang.org/u/wsshin)\
**Post date:** [March 6, 2023, 4:03pm UTC](https://discourse.julialang.org/t/difference-between-type-parameters-and-type-types/95622/1 "2023-03-06T16:03:13Z")

</div>

I am trying to retrieve the parameters of a parametric type, and find that both `parameters` and `types` fields of `Type` provide what I want:

```julia-repl
julia> VERSION
v"1.9.0-beta4"

julia> struct MyType{S,T}
           a::S
           b::T
       end

julia> m = MyType(1, 1.0)
MyType{Int64, Float64}(1, 1.0)

julia> typeof(m).parameters
svec(Int64, Float64)

julia> typeof(m).types
svec(Int64, Float64)

```

Is there any difference between the two?

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [March 6, 2023, 4:07pm UTC](https://discourse.julialang.org/t/difference-between-type-parameters-and-type-types/95622/2 "2023-03-06T16:07:16Z")

</div>

This might give you an idea:

```julia
julia> struct MyType2{S}
           a::S
           b::Float64
       end

julia> m = MyType2(1, 1.0)
MyType2{Int64}(1, 1.0)

julia> typeof(m).parameters
svec(Int64)

julia> typeof(m).types
svec(Int64, Float64)

```

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [March 6, 2023, 4:07pm UTC](https://discourse.julialang.org/t/difference-between-type-parameters-and-type-types/95622/3 "2023-03-06T16:07:48Z")

</div>

You can try the same with

```julia
struct MyType{S,T}
           a::S
           b::Vector{T} 
       end

```

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [March 6, 2023, 4:08pm UTC](https://discourse.julialang.org/t/difference-between-type-parameters-and-type-types/95622/4 "2023-03-06T16:08:29Z")

</div>

However I would say it is usually bad practice to access language internals that way. If you need these types somewhere, the better way would be to get them via dispatch:

```julia
function f(m::MyType{S,T}) where {S,T}
    # do something with S or T
end

```

---

<div class="post-metadata">

**Author:** ![mikmoore](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikmoore/32/31109_2.png) [@mikmoore](https://discourse.julialang.org/u/mikmoore)\
**Post date:** [March 6, 2023, 4:12pm UTC](https://discourse.julialang.org/t/difference-between-type-parameters-and-type-types/95622/5 "2023-03-06T16:12:10Z")

</div>

The “typical” way to extract these values is with functions like the following:

```julia
typeS(::Type{<:MyType{S,T}}) where {S,T} = S
typeT(::Type{<:MyType{S,T}}) where {S,T} = T

```

Internals like `<type>.parameters` are allowed to change in the future, so be warned that implementations using them may require revision in a later version.

You can also look into the `fieldtype` function.
