# Compatibility of Dict{String, Any} with Dict{String, String}

**URL:** <https://discourse.julialang.org/t/compatibility-of-dict-string-any-with-dict-string-string/9841>\
**Category:** General Usage\
**Tags:** dictionary\
**Created:** [March 20, 2018, 4:53pm UTC](https://discourse.julialang.org/t/compatibility-of-dict-string-any-with-dict-string-string/9841 "2018-03-20T16:53:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aliddell](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aliddell/32/3766_2.png) [@aliddell](https://discourse.julialang.org/u/aliddell)\
**Post date:** [March 20, 2018, 4:53pm UTC](https://discourse.julialang.org/t/compatibility-of-dict-string-any-with-dict-string-string/9841/1 "2018-03-20T16:53:41Z")

</div>

Hi all. I’m trying to pass an argument of type `Dict{String, String}` to a function with signature `Dict{String, Any}`, e.g.,

```julia
function foo(x::Dict{String, Any})
    x
end

```

When I invoke it like so:

```julia
foo(Dict("bar"=>"baz"))

```

I get

```julia
ERROR: MethodError: no method matching foo(::Dict{String,String})
Closest candidates are:
  foo(::Dict{String,Any}) at REPL[18]:2

```

I’m confused by this. Doesn’t a `Dict{String, String}` fall under the `Dict{String, Any}` category? I guess this is related to the disclaimer in [**Parametric Composite Types**](https://docs.julialang.org/en/stable/manual/types/#Parametric-Composite-Types-1), namely:

> This last point is _very_ important: even though `Float64 <: Real` we **DO NOT** have `Point{Float64} <: Point{Real}`.

What would be the correct thing to do here? I expect to pass `Dict`s keyed by `String` with arbitrary value types to `foo` (think JSON objects), but I don’t want `foo` to fail if the `Dict` happens to have the same type for all its values.

---

<div class="post-metadata">

**Author:** ![ggggggggg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ggggggggg/32/265_2.png) [@ggggggggg](https://discourse.julialang.org/u/ggggggggg)\
**Post date:** [March 20, 2018, 4:57pm UTC](https://discourse.julialang.org/t/compatibility-of-dict-string-any-with-dict-string-string/9841/2 "2018-03-20T16:57:55Z")

</div>

```julia
julia> function foo(x::Dict{String, <:Any})
           x
       end
foo (generic function with 1 method)

julia> foo(Dict("bar"=>"baz"))
Dict{String,String} with 1 entry:
  "bar" => "baz"

```

You just need to read the next few paragraphs below the big orange “Warning” from your link to find this in the docs.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 20, 2018, 5:00pm UTC](https://discourse.julialang.org/t/compatibility-of-dict-string-any-with-dict-string-string/9841/3 "2018-03-20T17:00:11Z")

</div>

`foo(x::Dict{String,<:Any}) = ...` is a useful shorthand here. This is explained in manual immediately after the warning you quoted. Even better, just do `foo(x::Dict{String}) = ...` (since omitted trailing type parameters are equivalent to `<:Any`).

---

<div class="post-metadata">

**Author:** ![aliddell](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aliddell/32/3766_2.png) [@aliddell](https://discourse.julialang.org/u/aliddell)\
**Post date:** [March 20, 2018, 5:01pm UTC](https://discourse.julialang.org/t/compatibility-of-dict-string-any-with-dict-string-string/9841/4 "2018-03-20T17:01:13Z")

</div>

D’oh. Thanks.
