These allow us to combine other types.

Notice: Here in line 22 - 25 the intersection is done based on the common type. Which is name in this case.

Note: Line 28 is a type guard at the runtime. There can be other type guards as well:


Here, you can see it is giving me an error. This is because it is not sure if privileges is present in the UnknownEmployee or not since we used a union type. Also we c eannot use the traditional typeof type guard here since the type will be object which is very generic. Also, we can’t even do this:

Since TS does not allow this. So, we can use the ‘in’ keywork provided by JS:

Notice: Line 38.
Similarly we can do:

Output:

We can also use instanceOf type guard like:
