Canonical guidance

Use when

Avoid

Preferred pattern

switch v := anyVal.(type) {
case string:
	return len(v)
case []byte:
	return len(v)
default:
	return 0
}

Anti-pattern

Explanation: This is tempting when cases share work, but type switches and expression switches have different rules and fallthrough does not bridge them.

Why

Related pages

Sources