Type 'ModuleWithProviders<NbThemeModule>' must have a '[Symbol.iterator]()' method that returns an iterator.ts(2488)

266 Views Asked by At

I try to use the Ngx-admin and set the themes but I've got the error: Type 'ModuleWithProviders' must have a 'Symbol.iterator' method that returns an iterator.ts(2488) how can I fix this error? plaese help me

export class ThemeModule {
    static forRoot(): ModuleWithProviders<ThemeModule> {
        return {
            ngModule: ThemeModule,
            providers: [
                ...NbThemeModule.forRoot(
                    {
                        name: 'default',
                    },
                    [DEFAULT_THEME, COSMIC_THEME, DARK_THEME],
                    null,
                    NbLayoutDirection.RTL
                    
                ),
            ],
        };
    }
}
2

There are 2 best solutions below

0
Alok Rajasukumaran On

The problem is with what comes to post the spread operator.

Do this way instead.

const nbThemeModule: any = NbThemeModule.forRoot(
                {
                    name: 'default',
                },
                [DEFAULT_THEME, COSMIC_THEME, DARK_THEME],
                null,
                NbLayoutDirection.RTL
                
            )

Then in the @ngModule,

export class ThemeModule {
  static forRoot(): ModuleWithProviders<ThemeModule> {
    return {
      ngModule: ThemeModule,
      providers: [
        ...nbThemeModule,
      ],
    };
  }
}

this will fix the issue which is a temporary hack.

0
Wescley On

I think it's due to strict compiler options flags in tsconfig.json.

In my case a simple fix it's:

export class ThemeModule {
  static forRoot(): ModuleWithProviders<ThemeModule> {
    return {
      ngModule: ThemeModule,
      providers: [
        ...NbThemeModule.forRoot(
          {
            name: 'default',
          },
          [ DEFAULT_THEME, COSMIC_THEME, CORPORATE_THEME, DARK_THEME ],
        ).providers || [],
      ],
    };
  }
}

Try just add || [] in the end.

I hope this will help you.