tc39 / proposal-nullish-coalescing

Nullish coalescing proposal x ?? y
https://tc39.github.io/proposal-nullish-coalescing/
1.23k stars 23 forks source link

Specify support for index access #18

Closed ArashMotamedi closed 6 years ago

ArashMotamedi commented 6 years ago

I'd like to suggest that the nullish-coalescing operator also be usable for index access:

let person = { name: "John" }
let cityLength = person.address?["city"]?.length
let repo = { 
   name: "myrepo",
   // commits: [{ date: "2017/12/01" }, {date: "2017/12/02"}]
 }
let firstCommitDate = repo.commits?[0]?.date;
tvald commented 6 years ago

I think you want the optional-chaining proposal. It already encompasses dynamic property access.

ArashMotamedi commented 6 years ago

@tvald Yes! Thanks! Perils of creating an issue way too late at night!