I'm still quite new to Typescript and have trouble wrapping my head around interfaces. As I understand an interface is a type description or a contract for a class. It allows me to define, which properties a class can have and of which type they are. I try to implement that, but always get this error:
error TS2420: Class 'ResultPage' incorrectly implements interface 'ResultPageInterface'.
Property 'entries' is missing in type 'ResultPage'.
Here is the code for the interface
export interface ResultPageInterface {
entries:Array<any>;
page_number:number;
page_size:number;
total_entries:number;
}
export class ResultPage implements ResultPageInterface {}
And here the class where I want to use it.
import { Injectable } from '@angular/core';
import { ResultPage } from '../interfaces/result-page.interface';
@Injectable()
export class SomeClass {
constructor() {}
buildPage(res:any): ResultPage {
let page:ResultPage = new ResultPage();
page.entries = res.data;
page.page_number = res.pagination.page_number;
page.page_size = res.pagination.page_size;
page.total_entries = res.pagination.total_entries;
return page;
}
}