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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.