DEV Community

Discussion on: TypeScript Type Guards and Type Predicates

Collapse
 
andi1984 profile image
Andreas Sander

Nice article, @stephanmeijer !

Functions that are declared as type predicate, must return a boolean. When the return value is true, TypeScript assumes that the return type is the one that's declared in the type predicate. If this function returns true, TypeScript assumes that the provided argument page is of type Article.

I learned about type predicates in the "TypeScript in 50 lessons" book and I was blown away by that, so I tried to explain myself in a video. But I really think your way of saying it is much more comprehensive :).