Intermediate
Write a Type Guard
isUser checks that unknown data is a User (an object with a text name and a number age), but its return type is plain boolean, so TypeScript doesn't narrow. Change the return type to a type predicate.
The checks call isUser on unknown data and use .name and .age inside the if.
What Check tests
- Your code has no type errors
- The console prints
ASHA 31andnot a usertwice isUsernarrows an unknown value
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
Runs in your browser. Your code is saved here.
Press Run to see the page.
Console
Nothing printed yet.