Today I Learned

2025/05/01

go

That wrapper types preserve type information in switch statements:

package main

import "fmt"

func main() {
	type x string
	y := x("asdf")
	z := any(y)
	switch z.(type) {
	case x:
		fmt.Println("cool")
	case string:
		fmt.Println("uh")
	}
}

https://go.dev/play/p/VkDckf3vp_O