Suggestion: "safe navigation operator", i.e. x?.y
Problem
Current Status The TC39 proposal is now at stage 3 (🎉🎉🎉🎉🎉) Implementation is in progress You can expect this feature in TypeScript 3.7 We'll update here when it's available in a nightly build Holding off on Optional Call until its semantics are clarified at committee Open questions What special-casing, if any, should `document.all` get? -------- Cand other languages have syntax sugar for accessing property chains where `null` (or in our case, `undefined`) might be encountered at any point in the object hierarchy. [code block] Need proposal on what exactly we should codegen, keeping in mind side effects of accessors. _____ Edit by @DanielRosenwasser February 27, 2018: This proposal is also called the "null propagation" operator.
Error Output
error console.log(x.y.q?.bar); // Should print 'undefined'
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: Suggestion: "safe navigation operator", i.e. x?.y
:+1: I'd like to see TypeScript gets this in first without having to wait for ESxx.
Trust Score
9 verifications
- 1
:+1: I'd like to see TypeScript gets this in first without having to wait for E
:+1: I'd like to see TypeScript gets this in first without having to wait for ESxx.
Validation
Resolved in microsoft/TypeScript GitHub issue #16. Community reactions: 135 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep