angular_analyzer_plugin icon indicating copy to clipboard operation
angular_analyzer_plugin copied to clipboard

Only allow non-directive ContentChild classes if they export themselves to the injector

Open MichaelRFairhurst opened this issue 8 years ago • 0 comments

Currently

@ContentChild(Object)
...

results in an error at the definition. Technically, this isn't always broken. I can bind my directives to the injector as type Object and they will be picked up:

@Component(selector: 'fooAsObject',
  providers: const [
    const Provider(Object, useExisting: FooAsObject)
  ])
class FooAsObject {...}

Ideally, we could warn people at the definition that using Object doesn't work. But it can work, so, we'll have to warn at the call site.

<my-container>
  <foo-not-as-object></foo-not-as-object> // warning: not transcluded
  <foo-as-object></foot-as-object> // OK
</my-container>

We'll just have to rely on people testing their components to get this right (for them to exercise the path where we will analyze their component for is-directive-ness).

But it has the benefit, that if someone uses base classes in an API like this:

  ContentChildren(AnySquare)

people will be able to create their own components that implement AnySquare and get feedback about when they aren't used correctly.

MichaelRFairhurst avatar Dec 11 '17 23:12 MichaelRFairhurst