web-dave/angular-starter-v2

Create a custom type

Opened this issue · 4 comments

  • Take a look at one Book Object Link
  • Generate a interface custom-types
  • Define two interface in this file
  • Use this interface as a type whenever we handle Books

generate

  ng g interface books/shared/custom-types

custom-types.ts

export interface IBook {
  title: string;
  subtitle: string;
  isbn: string;
  abstract: string;
  numPages: number;
  author: string;
  publisher: IUser;
}

export interface IUser {
  name: string;
  url: string;
}

e.g.

  books: IBook[];
  @Input() book: IBook;
  getBooks() {
    const url = this.restRoot;
    return this.http.get<IBook[]>(url);
  }