type switch

A switch statement written switch v := value.(type) that picks a branch by the concrete type inside an interface value.

In more detail

Each case names a type, and inside it v already has that type. A default case handles everything else. It is the tidy way to handle a small, known set of possible types.

Example

switch item := value.(type) {
case string:
case int:
default:
}

Related terms

Taught in

References