Search code examples
angulartypescripttypesclass-constructors

Typescript, Angular Class Constructor too many arguments


I'm trying to instantiate a class by using its constructor function. This is the class:

export class Response {
    id: number;
    phrase: string;
    response: any;

    constructor(id: number, phrase: string, response: any) {
        this.id = id;
        this.phrase = phrase;
        this.response = response;
    }
}

When I now try to instantiate it, the compiler throws an error: "Expected 0-2 arguments, but got 3."

This is my instantiation code that gets called:

observable.subscribe(response => {
    const newResponse = new Response(this.index+1, questionnaire.questions[this.index].phrase, response);
});

In my Angular-App I get the error code "Argument 2 of Response constructor can't be converted to a dictionary."... Can someone explain to me what is going on here?

Kind regards :-)


Solution

  • Looks like there's a conflict between the class name with what you have defined as Response

    enter image description here

    It's a predefined interface

    enter image description here

    Try changing name of your class and then check.