I'm feeling lost. I'm attempting to insert new objects into an array in TypeScript, but I encountered an error. My interface includes a function, and I'm puzzled. Can anyone offer guidance?
interface Videos{
title: string;
description: string;
like: number;
pressLike():void;
pressDislike():void;
}
class Video implements Videos{
public title: string;
public description: string;
public like: number;
constructor(title: string, description: string, like?: number){
this.title = title;
this.description = description;
this.like = like || 0;
}
public pressLike():void{
let ins_like = this.like;
if(ins_like < 0){
this.like = 0;
}else{
this.like++;
}
}
public pressDislike():void{
let ins_like = this.like;
if(ins_like < 0){
this.like = 0;
}else{
this.like--;
}
}
}
var videoArr: Videos[] = [
{"title": "Book 1 Water", "description": "Learn the water bending", "like": 0}
];
// The error occurs here when trying to add new videos to the array
The error mentions missing pressLike and pressDisplike properties, even though they are functions. How can I include them in the array?