I think the point is that people would like to write something like this: if (person?.address?.zipcode)
instead of this: if (person && person.address && person.address.zipcode) That appeals to me. On Thu, Oct 13, 2016 at 12:20 PM, Bob Myers <[email protected]> wrote: > Why is this needed? Why are people trying to get the property of an object > which is null? Why is the object null in the first place? This can probably > be considered poor program design. It's sort of like trying to dereference > a null pointer. In addition, parameter defaults and defaults in > destructuring may make this somewhat less of an issue. > > Note that TS2 is explicitly moving away from permitting null to be > assigned to something which is alleged to be an object. (Although TS2 has > "stolen" the `!` operator, it is merely a type assertion--a narrowing from > `object | null` to `object` as I understand it. It is not a run-time check.) > > But let's say we nevertheless think this is an important feature. It has > been discussed at great length here. No proposal has ever had the > inevitability, generality, or intuitiveness that would allow it to gain > traction. All the proposals are essentially little syntactic hacks. > > Can we find some more general extension to JS syntax that solves or > mitigates this problem as well as others? Kills two birds with one stone? > One that seems like a natural extension to current syntax, instead of an > extra magic character we stick somewhere to solve one specific problem? > > Just as an example, consider the following idiom for null propagation: > > ``` > a ? a.b ? a.b.c : undefined : undefined > ``` > > We can leverage this pattern by allowing the `:` in the ternary operator > to be omitted (defaulting to undefined), allowing us to write: > > ``` > a ? a.b ? a.b.c > ``` > > Whether you love it or hate it, at least this solves more problems that > just null propagation. I'm not seriously suggesting this. I'm just saying > we need to be more creative in brainstorming possible solutions to the > problem. > > -- > Bob > > > On Thu, Oct 13, 2016 at 9:37 PM, Claude Pache <[email protected]> > wrote: > >> >> Le 13 oct. 2016 à 17:14, Kagami Rosylight <[email protected]> a >> écrit : >> >> >> >IIRC the proposed syntax for computed properties was x?.[y], >> >> Yes you’re right, sorry :/ >> >> IMO it still seems the syntax problem is the main reason why this >> proposal has stalled. If not, what is the problem here? >> >> >> The issue with `?.[` is that it is considered as not pretty by some >> people. A syntax that is at the same time pretty, technically working, and >> not confusing is difficult to find. >> >> Concerning your suggestion of using `!`: From a technical point of view, >> using `![` instead of `?.[` may work only if you forbid a line terminator >> before the `!`, because the following program is valid as of today (with >> implied semicolons): >> >> ```js >> foo >> ![42] >> ``` >> >> I’m curious why this proposal is not even listed in stage 0 proposal list. >> >> >> Because no representative of TC39 has volunteered to champion it. >> >> —Claude >> >> >> _______________________________________________ >> es-discuss mailing list >> [email protected] >> https://mail.mozilla.org/listinfo/es-discuss >> >> > > _______________________________________________ > es-discuss mailing list > [email protected] > https://mail.mozilla.org/listinfo/es-discuss > > -- R. Mark Volkmann Object Computing, Inc.
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

