2016-12-20 23 views
0

基本的にはTypeScriptのコンパイルを参照して、私の問題の可能なすべての解決策を確認しました。AngularJS 2型スクリプトコンパイルエラー - 型の引数

Argument of type '{ declarations: (typeof NavbarComponent | typeof FooterComponent | typeof AboutComponent | typeof...' is not assignable to parameter of type 'NgModule'. 
    Types of property 'providers' are incompatible. 
    Type '(typeof BaseRequestOptions | typeof DataService | typeof UserService | typeof AuthenticationServi...' is not assignable to type 'Provider[]'. 
     Type 'typeof BaseRequestOptions | typeof DataService | typeof UserService | typeof AuthenticationServic...' is not assignable to type 'Provider'. 
     Type 'typeof DataService' is not assignable to type 'Provider'. 
      Type 'typeof DataService' is not assignable to type 'FactoryProvider'. 
      Property 'provide' is missing in type 'typeof DataService'. 
[default] /SYS/PROJECT/WEB/studio/front-studio/src/app/app.routing.ts:14:7 
    Type '({ path: string; component: typeof LoginComponent; } | { path: string; component: typeof HomeComp...' is not assignable to type 'Route[]'. 
    Type '{ path: string; component: typeof LoginComponent; } | { path: string; component: typeof HomeCompo...' is not assignable to type 'Route'. 
    Type '{ path: string; component: typeof HomeComponent; }' is not assignable to type 'Route'. 
     Types of property 'component' are incompatible. 
     Type 'typeof HomeComponent' is not assignable to type 'Type<any>'. 
      Cannot assign a 'private' constructor type to a 'public' constructor type. 
[default] Checking finished with 2 errors 

私は部品にタイプを追加しようとしましたが、それはまだ同じです:私はプロジェクトを開始するたびに私はこれらを持っています。アプリケーションは正常に動作しているので、TypeScriptのコンパイルの問題だと思います。

ルータもSublime Textでエラーを示しています。それが役立つ可能性がある場合

const appRoutes : Routes = [ 

     {  path: 'login', component: LoginComponent }, 

     {  path: '', component: HomeComponent }, 
     {  path: 'about', component: AboutComponent, canActivate: [AuthGuard] }, 

    // Otherwise redirect to home 
    { path: '**', redirectTo: '' } 
    //{ path: '**', component: PageNotFoundComponent } 
]; 

export const routedComponents = [HomeComponent, AboutComponent]; 
export const routing : ModuleWithProviders = RouterModule.forRoot(appRoutes); 

これは、私のTSconfigです:

{ 
    "compilerOptions": { 
    "target": "es5", 
    "module": "commonjs", 
    "moduleResolution": "node", 
    "sourceMap": true, 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "lib": [ "es2015", "dom" ], 
    "noImplicitAny": true, 
    "suppressImplicitAnyIndexErrors": true, 
    "typeRoots": [ 
     "../node_modules/@types" 
    ] 
    }, 
    "exclude": [ 
     "node_modules", 
     "typings/main", 
     "typings/main.d.ts" 
    ] 
} 

私は他に何を試すことができますか?どこからでもディレクティブを削除し、すべてのコンポーネントは@ngModule宣言にあります。私はほぼ一週間を過ごしましたが、私はまだこれに対する解決策を見つけられませんでした。

@ngModule:

... 

import { routing } from './app.routing'; 
import { AppComponent } from './app.component'; 
import { Component, Type } from '@angular/core'; 

@NgModule({ 

    // Components and directives 
    declarations: [ 
    AppComponent, 
    NavbarComponent, HomeComponent, ... 
    ], 

    // Module dependencies 
    imports: [ 
    BrowserModule, 
    FormsModule, 
    HttpModule, 
    routing, 
    SelectModule, 

    ], 

    schemas: [ CUSTOM_ELEMENTS_SCHEMA ], 

    // Services 
    providers: [ 

     DataService, 
     ... 


     ], 

    // Root component 
    bootstrap: [AppComponent], 

}) 

export class AppModule { 

} 
+1

@ngModuleを質問に追加できれば、問題を見つけるのに役立ちます。 –

+0

@ngModule – d123546

+0

更新されました。 plunkrで問題を再現してみて、少しでも遊べるリンクを教えてください。 – smnbbrv

答えて

7

私はそれぞれのサービスでプライベートコンストラクタを使用していたので、私は同じ問題を抱えていたし、私の場合には、それが発生しました。そのため、コンシューマをDataServiceに非公開にする、つまりprivateモディファイアを削除するという解決策があります。

0

また、親/基本クラスに「抽象」を追加したかどうかを確認してください。削除する必要があります。

+1

これは質問に答えず、代わりにコメントにする必要があります。 –

-1

私はプライベートコンストラクタAppComponentで同じ問題がありました。コンストラクタをpublicにして解決しました