The Problem
I faced an issue while de-structuring an optional nested property.
// product.js
export const productA = { name: 'A', price: { value: 20 } };
export const productB = { name: 'B' };
// index.js
import { productA, productB } from './product';
const { price: { value } } = productA;
/* the actual problem, it throws with the error
"cannot read property 'value' of undefined" */
const { price: { value } } = productB;
The Solution
Let me know, what do you guys think of it?
const { price?: { value } } = productB;
Thanks!