Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

245
Views
How to avoid destructuring undefined values in JavaScript?

I get response registryReportSettings from server:

this.getRegistrySettings(registry.Id).subscribe((registryReportSettings: { extended: ReportPropertiesRequest }) => {
  const { objectProperties, reportProperties, textProperties } = registryReportSettings?.extended;
}

If it is null I get an error:

TypeError: Cannot destructure property 'objectProperties' of '(intermediate value)(intermediate value)(intermediate value)' as it is undefined.

How to fix it using TS?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The error means that you try to deconstruct a possible undefined (Because you use optional chaining)

You can do

const { objectProperties, reportProperties, textProperties } = registryReportSettings?.extended ?? {};

So you will always deconstruct an object

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!