I want to add custom methods to my class definitions in Angular 2. But I get errors like the following when I try to then create mock objects (see the Angular 2 Tour of Heroes tutorial).
public/app/mock-searches.ts(3,14): error TS2322: Type '{ box: { x: number; y: number; width: number; height: number; }; dateCreated: Date; eventIdStr: s...' is not assignable to type 'Search[]'.
Type '{ box: { x: number; y: number; width: number; height: number; }; dateCreated: Date; eventIdStr: s...' is not assignable to type 'Search'.
Property 'refreshProducts' is missing in type '{ box: { x: number; y: number; width: number; height: number; }; dateCreated: Date; eventIdStr: s...'.
public/app/search.service.ts(33,40): error TS2304: Cannot find name 'err'.
refreshProducts(): void
is a method declared for the Search
class I'm trying to mock. How can I best resolve this error? Or am I trying to do something backwards, that may handled in a more conventional way in Angular 2?
search.ts (sample)
import { Rect } from './rect';
export class Search {
box: Rect;
dateCreated: Date;
products: Product[];
refreshProducts(): void {
// Do something useful
}
}
mock-searches.js (sample)
import { Search } from './search';
export const SEARCHES: Search[] = [
{
box: { x: 4, y: 4, width: 20, height: 20 },
dateCreated: new Date(),
products: []
}
];