Use the value.(type) syntax to safely extract a concrete type from an interface value in Go.
Use a type assertion to extract a concrete type from an interface value by appending the target type in parentheses to the variable. If the type is incorrect or the interface is nil, the program panics unless you use the comma-ok idiom to check the result safely.
var i interface{} = 42
if v, ok := i.(int); ok {
fmt.Println(v * 2)
} else {
fmt.Println("not an int")
}
A type assertion is like asking a box if it contains a specific item before you try to use it. It matters because Go interfaces can hold any type, so you need to confirm the actual type before accessing specific features. Use this when you have a generic value but need to perform operations specific to a known type.