# When are the types checked for values and parameters?

**URL:** <https://discourse.julialang.org/t/when-are-the-types-checked-for-values-and-parameters/12473>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [July 18, 2018, 4:49pm UTC](https://discourse.julialang.org/t/when-are-the-types-checked-for-values-and-parameters/12473 "2018-07-18T16:49:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gbenatt92](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gbenatt92/32/4583_2.png) [@gbenatt92](https://discourse.julialang.org/u/gbenatt92)\
**Post date:** [July 18, 2018, 4:49pm UTC](https://discourse.julialang.org/t/when-are-the-types-checked-for-values-and-parameters/12473/1 "2018-07-18T16:49:04Z")

</div>

To further clarify my question, does the type check only happen at “runtime” (when you execute something) or can it happen separately from it? Is there an option to force check the types aside from just running the code?

I’ve found this project [https://github.com/astrieanna/TypeCheck.jl](https://github.com/astrieanna/TypeCheck.jl) that does something similar in Julia but it’s abandoned.

What’ I’m thinking is something akin to [http://mypy-lang.org/](http://mypy-lang.org/), where you can check if the types are correct before you execute a code.

Although I know Julia will give an error when you run code where the types don’t match, this way of manual checking can be really useful for debugging purposes, and is something used daily by members of my team.

I mention this because I’m slowly convincing people at work that Julia is worth a try, and this came up as major question from one of the technical leaders.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [July 18, 2018, 4:52pm UTC](https://discourse.julialang.org/t/when-are-the-types-checked-for-values-and-parameters/12473/2 "2018-07-18T16:52:30Z")

</div>

This is definitely something we’d like to have in the future but it hasn’t become a top development priority just yet. If anyone’s interested in building a type checker (based on @astrieanna’s work or a fresh start), it would definitely be a great and useful project.

---

<div class="post-metadata">

**Author:** ![gbenatt92](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gbenatt92/32/4583_2.png) [@gbenatt92](https://discourse.julialang.org/u/gbenatt92)\
**Post date:** [July 18, 2018, 5:03pm UTC](https://discourse.julialang.org/t/when-are-the-types-checked-for-values-and-parameters/12473/3 "2018-07-18T17:03:57Z")

</div>

Thanks a lot for the answer! So the type is only checked when a code is executed, right?

I definitely would love to learn how to contribute for something like this (once I’m less green), maybe even convince said leader to help.

---

<div class="post-metadata">

**Author:** ![jonathanBieler](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)\
**Post date:** [July 18, 2018, 5:13pm UTC](https://discourse.julialang.org/t/when-are-the-types-checked-for-values-and-parameters/12473/4 "2018-07-18T17:13:17Z")

</div>

I don’t remember exactly when type inference get run for the first time, but it’s easy to run it yourself on a method and get the return type (it’s also stored in the method itself once it has been run IIRC). You can check this thread too:

> [@Enforcing function signatures by both argument & return types](https://discourse.julialang.org/t/enforcing-function-signatures-by-both-argument-return-types/8174):
>
> I’d like to pass a function (f) to another function (g) but g expects f to take some specific types of arguments and return a specific type. Is it possible to enforce that statically? For example, g() expects f to take a single integer argument and return another integer. So the following code is valid: julia\> foo(x::Int) = x + 1 foo (generic function with 1 method) julia\> g(f, v::Int)::Int = f(v) g (generic function with 1 method) julia\> g(foo, 10) 11 However, if I pass a function that d…

---

<div class="post-metadata">

**Author:** ![gbenatt92](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gbenatt92/32/4583_2.png) [@gbenatt92](https://discourse.julialang.org/u/gbenatt92)\
**Post date:** [July 18, 2018, 5:34pm UTC](https://discourse.julialang.org/t/when-are-the-types-checked-for-values-and-parameters/12473/5 "2018-07-18T17:34:53Z")

</div>

Interesting! This gives me some hints for implementing on my own code, but I’d definitely like to automate this type checking just like MyPy does. (and I bet this can be easier than Python since the type system is already built-in on Julia)
