A common mistake is using `any` for convenience when a function accepts or returns a known kind of value. In Go 1.18 and later, `any` is an alias for the empty interface, `interface{}`, which specifies no methods and can hold any value. Assigning a value to `any` discards useful type information, so callers need a type assertion before using it. section 2.8
An expressive API versus an unrestricted one
This API compiles, but its signatures hide what the store accepts and returns: func (s *Store) Get(id string) (any, error) func (s *Store) Set(id string, v any) error A caller can pass an unrelated value such as `42`, with no compile-time safeguard. Prefer explicit methods when the supported types are known: func (s *Store) GetContract(id string) (Contract, error) func (s *Store) SetContract(id string, contract Contract) error Clients that need only the contract operations can define a smaller interface themselves. section 2.8
Use `any` selectively:
- Use it when an operation genuinely accepts or returns any possible type, such as `json.Marshal` or variadic query arguments. section 2.17 section 2.8
- Prefer explicit signatures when the domain types are known; additional methods can remain expressive and type-safe. section 2.8
- Treat `map[string]any` as flexible but inspect decoded numeric values: JSON numbers become `float64`, including values written without decimals. section 10.3.3
func main() {
var i any
i = 42 #1
i = "foo" #2
i = struct { #3
s string
}{
s: "bar",
}
i = f #4
_ = i #5
}
func f() {}
Trace one `any` variable through assignments of an integer, string, struct, and function to see its unrestricted value shape. section 2.8



