3 ms·
if (!user || typeof user.nam !== 'string') { throw new Error("Missing or invalid 'nam' on user"); } Contemporary JavaScript has optional chaining, defaul
by joquarky 2y ago
if (!user || typeof user.nam !== 'string') {
throw new Error("Missing or invalid 'nam' on user");
}
Contemporary JavaScript has optional chaining, default values, and reflective tools like Object.hasOwn, which are all web standards. You just have to know how to use them.
- troupo 2y agoYou really don't understand what types give you, do you? Where are you going to put the code above in this: <section @name="user-details" class="user"> <media :image="/app/icon/cc/{cc}.svg" :title="name"> <p>{ email }</p> </media> <dl :if="org"> <dt>Company</dt> <dd>{ org }</dd> <dt>Country</dt> <dd> { country }</dd> <dt>Company size</dt> <dd>{ size.desc } ({ size.label })</dd> <dt>Website</dt> <dd><a class="action">{ website }</a></dd> <dt>Plan</dt> <dd><pill icon="dot" :label="{ plan }"/></dd> </dl> <media-thumbs :items="shots"/> <chat-thread :thread="thread"/> </section> Are you going to write ifs for every permutation of possible typos? (Let's ignore for a second that it's not just typos)