Skip to content

Suggestion: "safe navigation operator", i.e. x?.y #16

Closed
@RyanCavanaugh

Description

@RyanCavanaugh

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?

C# and 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.

var x = { y: { z: null, q: undefined } };
console.log(x?.y?.z?.foo); // Should print 'null'
console.log(x?.baz); // Still an error
console.log(x.y.q?.bar); // Should print 'undefined'

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

CommittedThe team has roadmapped this issueES NextNew featurers for ECMAScript (a.k.a. ESNext)SuggestionAn idea for TypeScriptUpdate Docs on Next ReleaseIndicates that this PR affects docs

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions