All academies
All challenges

Validate unknown Data with a Custom Guard

hardtype-guards200 XP

Problem

You receive parsed JSON typed as unknown. Define an interface User with name (string), age (number), and tags (string[]). Write isUser(value: unknown): value is User that returns true only when the value is a non-null object whose name is a string, whose age is a number, and whose tags is an array containing only strings. After a successful check, the value must be usable as a User with no casts.

Expected output

true
false
Ada has 2 tags

Hints

Stuck? Reveal hints one at a time.

Solution

Try solving it yourself first — revealing is always available.

Press Run in the editor — your console output is checked automatically.
No errors
Loading...

Console output appears here. Press Run or just type — the code compiles automatically.