design-to-code icon indicating copy to clipboard operation
design-to-code copied to clipboard

[Feature]: Improve the performance and readability of code to use Optional Chaining operators

Open janechu opened this issue 4 years ago • 0 comments

What package(s) should this feature be added to?

@microsoft/fast-tooling, @microsoft/fast-tooling-react

Summary

There are currently a lot of if statements that check objects for properties. These could be slightly more performant and readable using the Optional Chaining operator.

Example without Optional Chaining operator:

if (myObj.foo && myObj.foo.bar && myObj.foo.bar.bat) {
    const myVar = myObj.foo.bar.bat;
}

Example with Optional Chaining operator:

const myVar = myObj.foo?.bar?.bat?; // undefined if foo, bar or bat are undefined

janechu avatar Aug 06 '21 19:08 janechu