0

All of you must know about typescript's/ECMA2020 new feature optional chaining.out of curiosity i was looking for the implementation methodology in typscript playground

And i was Expecting implementation of

let obj = {
    name: {
        age: {
            what: {
                x:12
            }
        }
    }
}

console.log(obj?.name?.age?.what?.x);

this would be something like this in es6/7/8

console.log(obj&&obj.name&&obj.name.age&&obj.name.age.what&&obj.name.age.what.x)

But it looks something like this.

console.log((_c = (_b = (_a = obj === null || obj === void 0 ? void 0 : obj.name) === null || _a === void 0 ? void 0 : _a.age) === null || _b === void 0 ? void 0 : _b.what) === null || _c === void 0 ? void 0 : _c.x);

https://www.typescriptlang.org/play/?target=2#code/DYUwLgBA9gRgVhAvBA3gKApiA7AhgWxAC5UMtzcBzY08urAdwAtcwT17OsAPIgRgBMZLpgC+wuuPLjxaUJFhwBSWljyF2EitU0jGLNqr3legrZykWJMtAGMo2AM5RQAOmBRKACkUB+V+og-lRBrsys-twAlADcaHYOzm4e3ooCAQShIf7hYJGxQA

Can someone explain the advantage of doing something which normal people don't understand at first glance is used than the one i expected

Nambi N Rajan
  • 491
  • 5
  • 15
  • This question is closed ,but the problem is only with safari browser not in other browsers – Nambi N Rajan Mar 04 '20 at 16:59
  • 1
    `${` doesn't print a dollar, the `${}` is the template literal escape sequence, so if you want a dollar you need to put that on it too. eg. `$${this.......` But this would be the case in Chrome too, – Keith Mar 04 '20 at 17:07
  • But above issue is only there at safari.I found few thing related to $ symbol in replace function.Thanks though – Nambi N Rajan Mar 04 '20 at 17:16
  • looks like FF/Chrome don't fully follow the spec there, and take "$n" literally, if there are no capture groups, unlike safari. Still your bug though, and the dupe target explains it pretty well. – ASDFGerte Mar 04 '20 at 17:17

0 Answers0