How can I combine destructuring assignment and optional chaining? How can I combine destructuring assignment and optional chaining? typescript typescript

How can I combine destructuring assignment and optional chaining?


Use short circuit evaluation to get a fallback value (empty object) if the f?.config expression evaluate to undefined:

const { longFieldName } = f?.config || {};


You can use the default values.

const Foo = {}const { config: { longFieldName = "" } = {} } = Fooconsole.log(longFieldName) //''