Curriculum Errors & packaging Type assertions & type switches exercise 1 · mcq
Type assertions & type switches
Exercise 7 of theme 4.1 introduced type assertions (v.(T)).
Theme 5.2's errors.As is the wrap-aware version. This exercise
recaps the BARE assertion form — used when you have an error
interface value and KNOW it's a specific concrete type (no
wraps involved).
Pick the SAFE form that won't panic if the type doesn't
match.
TypeScript reference
About this theme
v.(T) asserts that an interface value v is actually of type T. Panics if wrong. Use the comma-ok form to check first: if t, ok := v.(T); ok { ... }. For multi-branch checks, switch v := i.(type) dispatches on dynamic type.