0

I get the following error when trying to add a descriptives array to my data and model. error TS2322: Type '{ "id": string; "name": string; "competency": string; "descriptives": string[]; "year": string; }[]' is not assignable to type 'Competency[]'. Type '{ "id": string; "name": string; "competency": string; "descriptives": string[]; "year": string; }' is not assignable to type 'Competency'. Types of property 'descriptives' are incompatible. Type 'string[]' is not assignable to type 'Descriptive[]'. Type 'string' is not assignable to type 'Descriptive'. app/app.routes.ts(9,36): error TS2307: Cannot find module './inventory/inventory.component'.

mocksCompetency.ts

    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 Answer 1

1

Your problem is here:

"descriptives" : ["Something More"]

According to your class, descriptives should be of type Descriptive[]. And Descriptive is defined as:

export class Descriptive {
     description: string;
}

This means that you should really be doing:

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

As an aside, you should probably be using interface instead of class for Competency and Descriptive.

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

1 Comment

Thanks for the response. It is tremendously helpful!

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.