typeover
curriculum

Curriculum Errors & packaging Type assertions & type switches exercise 5 · fill-word

Type assertions & type switches

Type the conventional name for the COMMA-OK boolean — the second value returned by a "safe" type assertion. Same convention you've used for map lookups (Module 2.2 exercise 4), channel receives (Module 6), and errors.As (theme 5.2).

TypeScript reference
Fill the blanks →

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.