Practice ยท 3 of 3
Exhaustive Switch
Write describeShape(v) where v is null | string | number | boolean | array. RETURN: "nothing" for null, "text" for strings, "number" for numbers, "flag" for booleans, "list of N" (with the length) for arrays, and for ANYTHING ELSE throw new Error("Unhandled shape") โ the runtime twin of the never-check.
Difficulty: intermediate
Press Submit to check your solution.
Back to lesson: Practice: Unions & Narrowing โ Practice