# Function output parametric type assertion

**URL:** https://discourse.julialang.org/t/function-output-parametric-type-assertion/31669
**Category:** General Usage
**Tags:** question
**Created:** [November 29, 2019, 5:22pm UTC](https://discourse.julialang.org/t/function-output-parametric-type-assertion/31669 "2019-11-29T17:22:24Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)
#### Post date: [November 29, 2019, 5:22pm UTC](https://discourse.julialang.org/t/function-output-parametric-type-assertion/31669/1 "2019-11-29T17:22:24Z")

</div>

So, I can assert the output type of a function like this (trivial example for demo purposes)

```nohighlight
 f(x)::Int = x

```

However, what if the output type depends on an input type parameter

```nohighlight
f(x::Vector{T})::T where T = x[1]

```

This produces an error and I don’t understand how I can assert the output type `T` correctly here.

How can I assert that the output type of a function is the input parameter `T` in general?

---

<div class="post-metadata">

### Author: ![thofma](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thofma/32/1691_2.png) [@thofma](https://discourse.julialang.org/u/thofma)
#### Post date: [November 29, 2019, 8:26pm UTC](https://discourse.julialang.org/t/function-output-parametric-type-assertion/31669/2 "2019-11-29T20:26:43Z")

</div>

I think this is a problem with the short function definition ([https://github.com/JuliaLang/julia/issues/21847](https://github.com/JuliaLang/julia/issues/21847) and [https://github.com/JuliaLang/julia/issues/31560](https://github.com/JuliaLang/julia/issues/31560))

The long version works as expected:

```julia
julia> function f(x::T)::T where {T}
         return x*1.0::T
       end
f (generic function with 1 method)

julia> f(2)
ERROR: TypeError: in typeassert, expected Int64, got Float64
Stacktrace:
 [1] f(::Int64) at ./REPL[4]:2
 [2] top-level scope at none:0

```

---

<div class="post-metadata">

### Author: ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)
#### Post date: [November 29, 2019, 10:32pm UTC](https://discourse.julialang.org/t/function-output-parametric-type-assertion/31669/3 "2019-11-29T22:32:05Z")

</div>

This seems to work:

```julia
julia> (f(x::Vector{T})::T) where {T} = x[1]
f (generic function with 1 method)

julia> f([3, 4])
3

```
