In C# I can write code to check for null references and in case throw a custom exception, example:
var myValue = (someObject?.SomeProperty ?? throw new Exception("...")).SomeProperty;
In recent updates TypeScript introduced the null coalescing operator ?? but using it like the above statement produces a compilation error. Is there some similar allowed syntax in TypeScript?
To clarify, the desired behavior is achieved with the following code:
if(someObject?.someProperty == null) {
throw new Error("...");
}
var myValue = someObject.someProperty.someProperty;
The code:
var myValue = someObject?.someProperty.someProperty;
works logically ok but throws a less meaningful exception.