I've been attempting to import a custom TypeScript class and initialize it for use with my view components. However, I encountered an error when trying to initialize the class:
Error message displayed in emulator
My import statement looks like this:
import GameModel from 'src/Rematch/Models/GameModel';
This is how my GameModel class is structured:
import { QuestionModel } from "./QuestionModel";
export default class GameModel {
public questions: QuestionModel[] = [];
constructor(private id: number = 0) {
this.getData(id);
}
getData(id: number) {
console.log(id);
this.questions.push(new QuestionModel(['Correct', 'Incorrect', 'Even more incorrect'], 'Correct', 'This is the first question. Answering correctly earns you points'));
this.questions.push(new QuestionModel(['Incorrect', 'Correct', 'Incorrect as well'], 'Correct', 'This is the second question. Answering correctly earns you points'));
this.questions.push(new QuestionModel(['Incorrect', 'Even more incorrect than before', 'Correct'], 'Correct', 'This is the third question. Answering correctly earns you points'));
this.questions.push(new QuestionModel(['This is also wrong', 'Correct', 'Incorrect'], 'Correct', 'This is the fourth question. Answering correctly earns you points'))
}
}
Upon typing:
const game: GameModel = new GameModel(1)
The error surfaces