0

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 :-)

1 Answer 1

1

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.

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

2 Comments

yes @Mridul. There is another one way If your import your Response interface from your respective file. Like @import { Response } from '../../../entities/response;
yes, thanks! I actually just had to import my Response class... x)

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.