0

I added google tag manager but keep getting error in angular:

static forRoot(config: GoogleTagManagerConfig): ModuleWithProviders; Type 'ModuleWithProviders' is not generic.

Doese anyone know how to solve this?

my package Manager: { "name": "demo-chat", "version": "0.0.0", "license": "MIT", "scripts": { "ng": "ng", "start": "ng serve", "build": "ng build --prod", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e" }, "private": true, "dependencies": { "@angular-devkit/core": "^7.0.3", "@angular/animations": "^6.0.2", "@angular/cdk": "^6.4.7", "@angular/common": "6.0.2", "@angular/compiler": "6.0.2", "@angular/core": "^6.0.3", "@angular/flex-layout": "^6.0.0-beta.15", "@angular/forms": "^6.0.3", "@angular/http": "6.0.2", "@angular/material": "^6.4.7", "@angular/material-moment-adapter": "^6.0.1", "@angular/platform-browser": "^6.0.3", "@angular/platform-browser-dynamic": "6.0.2", "@angular/router": "6.0.2", "@ng-bootstrap/ng-bootstrap": "^4.1.2", "@ngrx/effects": "^6.0.1", "@ngrx/entity": "^6.0.1", "@ngrx/store": "^6.0.1", "@ngrx/store-devtools": "^6.0.1", "angular-file-saver": "^1.1.3", "angular-file-uploader": "^4.1.3", "angular-google-tag-manager": "^1.2.4", "angular-image-cropper": "^1.2.0", "angular-material-fileupload": "0.0.11", "angular2-text-mask": "^9.0.0", "bn-ng-idle": "0.0.2", "core-js": "^2.4.1", "detect-browser": "^4.5.0", "hammerjs": "^2.0.8", "lodash": "^4.17.10", "moment": "^2.22.0", "ng-flash-messages": "^0.2.0", "ngx-drag-drop": "^1.1.0", "ngx-image-cropper": "^1.2.2", "ngx-infinite-scroll": "^0.8.4", "ngx-mat-select-search": "^1.4.2", "ngx-uploader": "^7.0.0", "ngxuploader": "^1.0.3", "node-latest-version": "^1.0.16", "rxjs": "^6.1.0", "rxjs-compat": "^6.1.0", "text-mask-addons": "^3.8.0", "vanilla-text-mask": "^5.1.1", "zone.js": "^0.8.26" }, "devDependencies": { "@angular-devkit/build-angular": "^0.6.8", "@angular/cli": "^6.0.8", "@angular/compiler-cli": "6.0.2", "@angular/language-service": "6.0.2", "@types/jasmine": "~2.8.3", "@types/jasminewd2": "~2.0.2", "@types/node": "~10.1.2", "codelyzer": "^4.0.1", "jasmine-core": "~3.1.0", "jasmine-spec-reporter": "~4.2.1", "karma": "~2.0.0", "karma-chrome-launcher": "~2.2.0", "karma-coverage-istanbul-reporter": "^2.0.0", "karma-jasmine": "~1.1.0", "karma-jasmine-html-reporter": "^1.1.0", "node-sass": "^4.9.2", "protractor": "~5.3.2", "sass-loader": "^7.1.0", "ts-node": "~6.0.3", "tslint": "~5.10.0", "typescript": "^2.7.2" } }

2 Answers 2

0

derror TS2315: Type 'ModuleWithProviders' is not generic means that this type is not generic. Generic type is defined at implementation and passes Types from <> to inner implementation and it depends on passed types. So probably you have copied code from diffferent version of the same lib. You just have to remove braces <> and it looks like:

static forRoot(config: GoogleTagManagerConfig) { }

Read more about generic types JavaScript

If You create type User like

export class User {
  name: string;
  platform: any;
}

You have no control over platform type but still You can assign there anything. Let's reimplement this to use generic type:

export class User<T> {
  name: string;
  platform: T;
}

And now we can use this like

const User<passed type here will be type of all ocurrences for T in Your implementation>

const User<Android>: androidUser = {
  name: 'Android user',
  platform: {
    version: 13,
    name: 'KitKat'
  } as Android
}

You still can pass any there but you should not.

Sign up to request clarification or add additional context in comments.

Comments

-1
static forRoot(config: GoogleTagManagerConfig): ModuleWithProviders<unknown>; 

You should provide the type. If you know which it is, it's better to be specific offcourse :)

3 Comments

ERROR in node_modules/angular-google-tag-manager/lib/angular-google-tag-manager.module.d.ts(4,53): error TS2315: Type 'ModuleWithProviders' is not generic.
I think manually adding something won't be good.
this error meanst that this type is not generic so passing unknown will give the same error cause if type is not generic then you can not pass anything cause in simple way Type does not have this braces <> in it, look at my answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.