2016-11-07 13 views
0

データとモデルに記述型配列を追加しようとすると、次のエラーが発生します。 エラーTS2322: '{"id":string; "name":文字列; "competency":文字列; "記述子":文字列[]; "年":文字列; } [] 'は型' Competency [] 'に割り当てられません。 '{"id":string; "name":文字列; "competency":文字列; "記述子":文字列[]; "年":文字列; } 'は、コンピテンシータイプに割り当てられません。 プロパティ 'descriptives'の種類は互換性がありません。 タイプ 'string []'はタイプ 'Descriptive []'に割り当てられません。 'string'タイプは 'Descriptive'タイプに割り当てられません。 app/app.routes.ts(9,36):エラーTS2307:モジュール './inventory/inventory.component'が見つかりません。角型2のモデルとデータに型式付きの配列を追加

import { Competency } from './competency'; 
    export const COMPETENCY: Competency[] = [ 
{ 
    "id": "EngLA001", 
    "name": "Oral Language", 
    "competency": "The teacher understands the importance of oral language, knows the development processes of oral language and provides the students with varied opportunities to develop listening and speaking skills.", 
    "descriptives": ["Something","More"], 
    "year": "2014", 
} 
    ]; 

competency.ts

export class Competency { 
    id: string; 
    name: string; 
    competency: string; 
    descriptives: Descriptive[]; 
    year: string; 
    } 
    export class Descriptive { 
     description: string; 
    } 

答えて

1

mocksCompetency.tsはあなたの問題はここにある:

"descriptives" : ["Something More"] 

あなたのクラスによると、descriptivesはタイプDescriptive[]でなければなりません。 Descriptiveは次のように定義されて:

export class Descriptive { 
    description: string; 
} 

これは、あなたが本当にやるべきことを意味します

"descriptives": [{description: "Something More"}] 

を脇に、あなたはおそらくCompetencyDescriptiveためinterface代わりのclassを使用する必要があります。

+0

お返事ありがとうございます。それは大いに役立ちます! – ryegrammer

関連する問題