Vscode-ng-language-service: Feature Request: turn off certain error messages

Created on 10 Jan 2019  路  10Comments  路  Source: angular/vscode-ng-language-service

I really love this extension because it helps a lot in debugging. However we have a project structure that leads to a bunch of false errors.

We dynamically load chunks from dynamically created URLs across packages. We load some components this way and we create an NgModule dynamically when the chunk is loaded. Something like this:

// Load components from another package
const loadedComponents = await import('our-other-package/' + dependencyName);
// Create NgModel from the loaded components with custom imports
const module = new NgModule({ components: loadedComponents, imports: [stuff1, stuff2] })

I see "Component X is not included in a module" errors in the _other package_ where we define the components. And yes: there's no NgModule there. But in this case the Language Service won't know whether a component will be used in any NgModules anywhere else. Nor will it know the available component selectors in the template as the imports of the dynamically created NgModule may contain practically anything.

Feature Request: an option to disable some of the error types. Specifically these 2 below, but you may consider making it configurable.

  • [Angular] Component 'MyComponentForDynamicNgModuleInAnotherPackage' is not included in a module and will not be available inside a template. Consider adding it to a NgModule declaration
  • [Angular] 'my-custom-component' is not a known element: ...
feature lib tracking in angular user XP

Most helpful comment

@yglin I eventually found out that if you don't export your mock component, it does not trigger the warning. So if you don't reuse the mock components and don't need to export it you're good (I don't know why we had some exported mock components in the first place, probably due to copy&paste laziness).

All 10 comments

This would be also useful for Components in Unit tests. They get included in a TestingModule which is not picked up by the language service.

Is there any discussion on this? I also have a dynamic import on NgModule that works perfectly but angular language service throws error for all component that is not directly imported by any module.

At least should exists a @angular-ignore tag for this.

Thanks for the suggestion, I think this should be a "warning" or a "suggestion" instead of an error, and user should be able ignore them. A new version of the language service is in the works (in conjuction with Ivy), and I hope to address it soon.

+1

+1, for the same reason of @t-animal, mocking a component in unit-test also triggers this error

It also affects modules for stories.

And, I don't need any warning or suggestion for it, I just want to disable it.

@yglin I eventually found out that if you don't export your mock component, it does not trigger the warning. So if you don't reuse the mock components and don't need to export it you're good (I don't know why we had some exported mock components in the first place, probably due to copy&paste laziness).

@t-animal bullseye~!!
I checked the problematic mock component and it did has export directive.
I don't recall the reason but probably for reuse or so.
THANX~!!

This is an important feedback regarding unit test components. The error message might contain a short info on not exporting the mock components. This message might help some of the developers.

However, there are other use-cases (like the one I've described in the original post, and probably the one mentioned by @JounQin) where this error message still should be disabled completely.

However, there are other use-cases (like the one I've described in the original post, and probably the one mentioned by @JounQin) where this error message still should be disabled completely.

There is an open issue tracking this: https://github.com/angular/angular/issues/32663 馃檪

Was this page helpful?
0 / 5 - 0 ratings