ngneat / effects

🪄 A framework-agnostic RxJS effects implementation
https://www.netbasal.com
MIT License
63 stars 11 forks source link

Effects NG: Build error, when using Directive Effects with angular 15 #55

Closed TobbiAR closed 1 year ago

TobbiAR commented 1 year ago

Which @ngneat/effects-* package(s) are the source of the bug?

effects-ng

Is this a regression?

Yes

Description

When using the useDirectiveEffects function of @ngneat/effects-ng with angular 15 of, I get the following error:

Error: src/app/app.component.ts:9:21 - error NG1010: Host directive must be a reference
  Value could not be determined statically.

9     hostDirectives: [useDirectiveEffects(Test1Effect)]
                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  src/app/app.component.ts:9:22
    9     hostDirectives: [useDirectiveEffects(Test1Effect)]
                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Unable to evaluate this expression statically.
  src/app/app.component.ts:9:22
    9     hostDirectives: [useDirectiveEffects(Test1Effect)]
                           ~~~~~~~~~~~~~~~~~~~
    A value for 'useDirectiveEffects' cannot be determined statically, as it is an external declaration.

Error: src/app/app.module.ts:9:9 - error NG6001: The class 'AppComponent' is listed in the declarations of the NgModule 'AppModule', but is not a directive, a component, or a pipe. Either remove it from the NgModule's declarations, or add an appropriate Angular decorator.

9         AppComponent,
          ~~~~~~~~~~~~

  src/app/app.component.ts:11:14
    11 export class AppComponent {
                    ~~~~~~~~~~~~
    'AppComponent' is declared here.

Please provide a link to a minimal reproduction of the bug

https://github.com/TobbiAR/effects-ng-directive-issue

Please provide the exception or error you saw

Error: src/app/app.component.ts:9:21 - error NG1010: Host directive must be a reference
  Value could not be determined statically.

Please provide the environment you discovered this bug in

I've attached the link to a minimal reproduction repostory with a single "app.component", on which the "hostDirectives" with "useDirectiveEffects" is used. The error also occurs, if I use the "useDirectiveEffects" on standalone components.

To reproduce the bug simply run "npm run start".

Anything else?

No response

Do you want to create a pull request?

No

EricPoul commented 1 year ago

@NetanelBasal I looked and this does not work in the app despite working in the tests. Angular doesn't allow us to use a function that returns a Type for hostDirectives. If this feature is needed we could use the next syntax

@Component({
  ...
  providers: [provideDirectiveEffects(TodoEffects)],
  hostDirectives: [EffectsDirective],
})

I don't think we can do much here.

NetanelBasal commented 1 year ago

You can start with the change. I will take a closer look asap.