TSworkingts-evergreen

User-defined type guards

Teach the compiler what you already know.

A function returning arg is T (or asserts arg is T) hands the compiler proof it cannot derive on its own — so narrowing survives across calls, filters, and runtime validation.

A basic isString predicate

TSintro
Press Run to execute

Only 'hello' enters the narrowed branch and prints HELLO; the 42 and null calls both fall through to (not a string). The predicate, not a cast, is what made value.toUpperCase() type-safe inside the if.