# Unexpected type change - Type declarations

**URL:** https://discourse.julialang.org/t/unexpected-type-change-type-declarations/4177
**Category:** New to Julia
**Created:** [June 9, 2017, 1:54pm UTC](https://discourse.julialang.org/t/unexpected-type-change-type-declarations/4177 "2017-06-09T13:54:06Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![hpoit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hpoit/32/245_2.png) [@hpoit](https://discourse.julialang.org/u/hpoit)
#### Post date: [June 9, 2017, 1:54pm UTC](https://discourse.julialang.org/t/unexpected-type-change-type-declarations/4177/1 "2017-06-09T13:54:06Z")

</div>

> This feature is useful for avoiding performance “gotchas” that could occur if one of the assignments to a variable changed its type unexpectedly.

> This “declaration” behavior only occurs in specific contexts:

> local x::Int8 # in a local declaration  
> x::Int8 = 10 # as the left-hand side of an assignment

> and applies to the whole current scope, even before the declaration.

[https://docs.julialang.org/en/stable/manual/types/#type-declarations](https://docs.julialang.org/en/stable/manual/types/#type-declarations)

Anyone care to expand on these specific contexts?

Valid example for local declaration?

```julia
for i=1:10
    local x::Int64
    x = i + functionthatunexpectedlychangestype(i)
end

```

Also not clear is the “even before the declaration”

---

<div class="post-metadata">

### Author: ![hpoit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hpoit/32/245_2.png) [@hpoit](https://discourse.julialang.org/u/hpoit)
#### Post date: [June 9, 2017, 3:20pm UTC](https://discourse.julialang.org/t/unexpected-type-change-type-declarations/4177/2 "2017-06-09T15:20:00Z")

</div>

“even before the declaration”: [https://docs.julialang.org/en/stable/manual/performance-tips/#type-declarations](https://docs.julialang.org/en/stable/manual/performance-tips/#type-declarations) I’m clipping this to the Types section in my notebook
