Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Null coalescing operator in React JS/ Typescript [duplicate]

We have the Null coalescing operator in .NET and we can use as below

string postal_code = address?.postal_code;

Same thing can we do in React JS?

What i found like we can do with && operator

in address.ts file

string postal_code = address && address.postal_code;

what i need like .net feature is possible in typescript with react JS, is that possible ?

something like:

string postal_code = address?.postal_code // I am getting the error in this line if I try to use like .NET
like image 262
Praveen Kumar Avatar asked Apr 17 '18 07:04

Praveen Kumar


1 Answers

This is a proposed feature in TypeScript, under the legendary Issue #16

It won't be introduced into TypeScript until the ECMAScript spec for this feature is firm as there is a desire for the TypeScript implementation to follow that specification - so you'll get it early, but not massively early in this case.

It is referred to as any of the following:

  • Null Propagation Operator
  • Existential Operator
  • Null Coalesce Operator
like image 121
Fenton Avatar answered Oct 26 '22 23:10

Fenton