How to achieve this in crystal?

myhash : Hash(String, String  ????? ) = { "name" => "test, "age" => 99}

puts myhash

i want the word age to be a string but its value should be number how ?

You could do

myhash : Hash(String, String | Int32) = {"name" => "test", "age" => 99}
puts myhash

You could also do this to get the type of the literal:

puts typeof({"name" => "test", "age" => 99})
2 Likes

doesn’t work my mate

How doesn’t it work? Can you give me an error message?

1 Like

sorry it works

1 Like