Sometimes in JavaScript, we have an object which we need to conform to a specific set of keys. This is possible through type enforcement in TypeScript, but if we want to do certain things if the keys don't exist, then we have to take a different approach.
For example, suppose we are receiving the following object from an array, where firstName
, lastName
, and age
are all needed for an operation we want to complete. For example