design-to-code
design-to-code copied to clipboard
[Feature]: Improve the performance and readability of code to use Optional Chaining operators
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