Implementing the getNewBookDetails method using keyof and typeof

The getNewBookDetails method will simply retrieve values for the different fields in the new book creation form (in a specific book collection) and will create a Book object corresponding to those values.

Let's add the code for it.

First, add the method and some defensive checks:

getNewBookDetails(collectionIdentifier: string): { error?: string, book?: Book } {      if (!collectionIdentifier) { 
        // we throw this one because it means that there is a bug! 
        throw new Error("The collection identifier must be         provided!"); 
    } 
    // required 
    const newBookForm = document.getElementById(`newBook-$ {collectionIdentifier}`) as HTMLFormElement; if (!newBookForm) { throw new Error(`Could not find ...

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.