web-dev-qa-db-ja.com

ANGULAR 6:エラーTS2315:タイプ 'ModuleWithProviders'はジェネリックではありません

こんにちは、私は何にも関係できない問題を経験しています。

私はそれがどんな用途にも使えることを望んでいる私のコードのいくつかを示しています。

リアクティブフォームの作成を開始すると、問題が発生したことを考慮してください。

まず第一に、ここに私のpackage.jsonがあります:

{
  "name": "name",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^6.0.3",
    "@angular/common": "^6.0.3",
    "@angular/compiler": "^6.0.3",
    "@angular/core": "^6.0.3",
    "@angular/forms": "^6.1.2",
    "@angular/http": "^6.0.3",
    "@angular/platform-browser": "^6.0.3",
    "@angular/platform-browser-dynamic": "^6.0.3",
    "@angular/router": "^6.0.3",
    "@ng-bootstrap/ng-bootstrap": "^2.2.0",
    "core-js": "^2.5.4",
    "rxjs": "^6.0.0",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular/compiler-cli": "^6.0.3",
    "@angular-devkit/build-angular": "~0.6.8",
    "TypeScript": "~2.7.2",
    "@angular/cli": "~6.0.8",
    "@angular/language-service": "^6.0.3",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.2.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~1.7.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.0",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.3.0",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1"
  }
}

そして、ここに私のAppモジュール:

import {BrowserModule} from '@angular/platform-browser';
import {ModuleWithProviders, NgModule} from '@angular/core';
import {AppComponent} from './app.component';
import {SideBarComponent} from './components/side-bar/side-bar.component';
import {HttpRequestProcessComponent} from './components/http-request-process/http-request-process.component';
import {ProcessFormComponent} from './components/form/process-form/process-form.component';
import {HttpResponseComponent} from './components/http-response/http-response.component';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import {HttpClientModule} from '@angular/common/http';
import {RouterModule, Routes} from '@angular/router';
import {RuleFormComponent} from './components/form/rule-form/rule-form.component';
import {ProcessComponent} from './components/process/process.component';
import {TestCasesComponent} from './components/test-cases/test-cases.component';
import {FilterPipe, SortByPipe} from './pipes/filter.pipe';
import {SalableProductFormComponent} from './components/form/salable-product-form/salable-product-form.component';
import {CheckOrderFormComponent} from './components/form/check-order-form/check-order-form.component';
import {ModalComponent} from './components/modal/modal.component';
import {HttpProcessiComponent} from "./components/http-textarea/http-processi/http-processi.component";
import {HttpRegoleComponent} from "./components/http-textarea/http-regole/http-regole.component";
import {HttpProdottiVendibiliComponent} from "./components/http-textarea/http-prodotti-vendibili/http-prodotti-vendibili.component";

const appRoutes: Routes = [
  {
    path: '',
    redirectTo: 'processi',
    pathMatch: 'full'
  },
  {
    path: 'processi',
    component: ProcessComponent,
    children: [
      {
        path: '',
        component: ProcessFormComponent,
        outlet: 'form'
      }
    ]
  },
  {
    path: 'regole',
    component: ProcessComponent,
    children: [
      {
        path: '',
        component: RuleFormComponent,
        outlet: 'form'
      }
    ]
  },
  {
    path: 'verifica-ordini',
    component: ProcessComponent,
    children: [
      {
        path: '',
        component: CheckOrderFormComponent,
        outlet: 'form'
      }
    ]
  },
  {
    path: 'prodotti-vendibili',
    component: ProcessComponent,
    children: [
      {
        path: '',
        component: SalableProductFormComponent,
        outlet: 'form'
      }
    ]
  }
];

const alternativeRoute = [
  {
    path: '',
    redirectTo: 'processi',
    pathMatch: 'full'
  },
  {
    path: 'processi',
    component: ProcessFormComponent
  },
  {
    path: 'regole',
    component: RuleFormComponent
  },
  {
    path: 'verifica-ordini',
    component: CheckOrderFormComponent,
  },
  {
    path: 'prodotti-vendibili',
    component: SalableProductFormComponent,
  }
];

export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);


@NgModule({
  declarations: [
    AppComponent,
    SideBarComponent,
    HttpRequestProcessComponent,
    ProcessFormComponent,
    HttpResponseComponent,
    RuleFormComponent,
    ProcessComponent,
    TestCasesComponent,
    FilterPipe,
    SortByPipe,
    SalableProductFormComponent,
    CheckOrderFormComponent,
    // ProductFormElementComponent,
    ModalComponent,
    HttpProcessiComponent,
    HttpRegoleComponent,
    HttpProdottiVendibiliComponent
  ],
  imports: [
    BrowserModule,
    HttpClientModule,
    RouterModule.forRoot(appRoutes,
      {enableTracing: false}),
    FormsModule,
    ReactiveFormsModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})

export class AppModule {
}

正確なエラーは次のとおりです。

node_modules/@angular/forms/src/form_providers.d.ts(22,9)のエラー:エラーTS2315:タイプ 'ModuleWithProviders'はジェネリックではありません。

それは私のコードに直接関係していないようですが、代わりにAngularのより深い設定レベルの何かです。

私のコンポーネントのいずれかでエラーが表示されます。

どうぞどうぞ。

[〜#〜] edit [〜#〜]ルート設定を次のように変更しました:

const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes, enableTracing: false});

そして、ルーティングをimportsに追加しました。問題はまだ残っています。

6
Teskin

フォームモジュールのリリースがコアと一致していません。

"dependencies": {
  ...
  "@angular/core": "^6.0.3",
  "@angular/forms": "^6.1.2",

修正するには、yarn add @angular/[email protected]またはnpm install @angular/[email protected](どちらのインストーラーを使用した場合でも)を使用してフォームを再インストールします。
その後調整が必要な他の依存関係がある可能性があるため、インストーラーが通知する必要があります。

Githubでform_providers.tsの6.0.3および6.1.2ソースを比較すると、これがエラーの原因となる変更です。

6.0.3

import {ModuleWithProviders, NgModule} from '@angular/core';
...
export class ReactiveFormsModule {
  static withConfig(opts: {
    /** @deprecated as of v6 */ warnOnNgModelWithFormControl: 'never' | 'once' | 'always'
  }): ModuleWithProviders {

6.1.2

import {ModuleWithProviders, NgModule} from '@angular/core';
...
export class ReactiveFormsModule {
  static withConfig(opts: {
    /** @deprecated as of v6 */ warnOnNgModelWithFormControl: 'never' | 'once' | 'always'
  }): ModuleWithProviders<ReactiveFormsModule> {
12
Richard Matsen