# Dict Types Behavior

**URL:** <https://discourse.julialang.org/t/dict-types-behavior/17097>\
**Category:** Internals & Design\
**Created:** [November 2, 2018, 7:18pm UTC](https://discourse.julialang.org/t/dict-types-behavior/17097 "2018-11-02T19:18:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![PauloXavier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pauloxavier/32/5897_2.png) [@PauloXavier](https://discourse.julialang.org/u/PauloXavier)\
**Post date:** [November 2, 2018, 7:18pm UTC](https://discourse.julialang.org/t/dict-types-behavior/17097/1 "2018-11-02T19:18:41Z")

</div>

I was working with Dict recently and found some strange behavior, i dont know if its meant to be this way, but i got curious about the reasoning(if intended).

```julia
julia> Dict{Symbol,Union{Missing,Any}}()
Dict{Symbol,Any} with 0 entries

julia> dict = Dict{Symbol,Union{Missing,Any}}()
Dict{Symbol,Any} with 0 entries

julia> push!(dict,:a => missing, :b => "string")
Dict{Symbol,Any} with 2 entries:
  :a => missing
  :b => "string"

```

Here i pass explicitly the type of the dict, and Julia returns `Dict{Symbol, Any}`. As missing is a type too, converting to `Any` would be ok. But here is where i think its inconsistent:

```julia
julia> Dict(:a => missing, :b => "string")
Dict{Symbol,Union{Missing, String}} with 2 entries:
  :a => missing
  :b => "string"

```

In this case, passing directly on the constructor, it’s built with the desired type.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [November 2, 2018, 7:19pm UTC](https://discourse.julialang.org/t/dict-types-behavior/17097/2 "2018-11-02T19:19:53Z")

</div>

```julia
julia> Union{Missing,Any}
Any

```

---

<div class="post-metadata">

**Author:** ![PauloXavier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pauloxavier/32/5897_2.png) [@PauloXavier](https://discourse.julialang.org/u/PauloXavier)\
**Post date:** [November 2, 2018, 7:22pm UTC](https://discourse.julialang.org/t/dict-types-behavior/17097/3 "2018-11-02T19:22:13Z")

</div>

Yes, it makes sense, but in the second example shouldnt the Dict have the type `Any`

, instead of `Union{Missing,Any}` too?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [November 2, 2018, 7:24pm UTC](https://discourse.julialang.org/t/dict-types-behavior/17097/4 "2018-11-02T19:24:47Z")

</div>

It doesn’t have `Union{Missing,Any}` it has `Union{Missing, String}`.

---

<div class="post-metadata">

**Author:** ![PauloXavier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pauloxavier/32/5897_2.png) [@PauloXavier](https://discourse.julialang.org/u/PauloXavier)\
**Post date:** [November 2, 2018, 7:30pm UTC](https://discourse.julialang.org/t/dict-types-behavior/17097/5 "2018-11-02T19:30:36Z")

</div>

I see, thanks! Got it now.
