Weird implicitly opened existential behaviour

You can get the static type of a value by dispatching through a generic context:

func staticType<T>(of _: T) -> String {
    return "\(T.self)"
}

print(type(of: 1 as Any)) // → "Int"
print(staticType(of: 1 as Any)) // → "Any"

Courtesy of @Joe_Groff: Printing the Static Type of a Value - #2 by Joe_Groff

6 Likes