Implementing the book method

Next, let's copy and adapt the createBook method.

For this one, we need to add a book: Book parameter. That way, users of the service will be able to pass in the book to add to the collection.

Here is the new code for this method:

createBook(collectionIdentifier: string, book: Book): void { 
  if (!collectionIdentifier) { 
    throw new Error('The collection identifier is required to create a     new book!'); 
  if (!this._bookCollections.has(collectionIdentifier) ||     !this._bookCollections.get(collectionIdentifier)) { 
    console.error('Tried to add a book to an unknown collection.     Identifier: ', collectionIdentifier); 
    this.displayErrorMessage('Failed to create the new book!'); 
  const existingCollection =  this._bookCollections.get(collectionIdentifier); ...

Get Learn TypeScript 3 by Building Web Applications now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.