Skip to content
angular challenges logoAngular Challenges

🔴 Typed ContextOutlet

You can improve template type checking for custom directives by adding template guard properties to your directive definition. Angular offers the static function ngTemplateContextGuard to strongly type structural directives.

However, the context of NgTemplateOutlet type is Object. But with the help of the above guard, we can improve that behavior.

In this exercise, we want to learn how to strongly type our ng-template in our AppComponent.

This exercise has two levels of complexity.

Currently, we have the following piece of code.

Unknown Person

As we can see, name is of type any. We want to infer the correct type using the custom directive PersonDirective.

Currently, we have the following piece of code.

Unknown Student

As we can see, student is of type any. We want to infer the correct type using the custom directive ListDirective.

But in this part, we want to pass a list of any object to ListComponent. And we still want the correct type to be inferred.