3 ms·
Just use lodash for that. Your example would become: // this won't throw an exception if foo is null _.get(foo, 'bar.baz') And you can even set a default
by lobo_tuerto 8y ago
Just use lodash for that.
Your example would become:
// this won't throw an exception if foo is null
_.get(foo, 'bar.baz')
And you can even set a default value to return if it is:
https://lodash.com/docs/4.17.11#get https://lodash.com/docs/4.17.11#get
- freewilly1040 8y agoThe point isn't that it's an unsolvable problem, the point is that you have to resort to clunky syntax or a 3rd party library to do this. And for something as basic as this, there's probably a number of different libraries that solve the same problem a slightly different way.
- hombre_fatal 8y agoYou lose all static analysis with that including Typescript checking/inference.