Type guards allow code to test that a variable is of a specific type. If the test succeeds, TypeScript's compiler understands the variable has the characteristics of that type within a block of code. This makes it possible to catch defects and provide context-specific auto-completion in the code block.
Learn more about type guards: https://jlik.me/ffu