Type assertion extracts the concrete type from an interface value. A type switch checks multiple possible types in sequence, and is commonly used when handling JSON or errors.
Real-world use: encoding/json unmarshals into interface{} where numbers become float64, objects become map[string]interface{}, and arrays become []interface{}. Type switches are essential for processing such dynamic data safely.
You're given an interface{} that could be either a string or an int. How would you safely print its value without causing a panic?
You have a function that returns interface{} and you know it's either []string or []int. How would you handle both cases without crashing?
Our plugin system returns interface{} from different modules, and we're getting random panics in production when users upload malformed configs. How would you debug and fix this?
We're unmarshaling JSON into a map[string]interface{} and need to extract nested values. When should you use type switches vs. nested type assertions, and why?
Our API gateway receives dynamic payloads from 10+ upstream services, all returning interface{} with varying structures. How would you design the type dispatch layer for performance and maintainability?
We're migrating from a hardcoded type handler to a plugin-based system using interface{}. What are the performance tradeoffs of type switches vs. reflection, and how would you benchmark them?
We have a legacy system using interface{} and type switches across 20+ microservices, and it's becoming a maintenance nightmare. How would you design a migration path to a more type-safe architecture without breaking clients?
A cross-team service uses type switches to handle protocol variants from different vendors. How do you enforce consistency, avoid runtime surprises, and document expected types across teams?