Is there a way to implement a TryGet pattern similar to C#'s out in TypeScript?
For instance:
if(TryGetFoo(out Foo foo)
{
Debug.Log("Got the foo, and here is it's bar: " + foo.bar);
}
else {
Debug.Log("Can't get the foo!");
}
The idea is that the function would return a boolean while the out parameter retrieves the value/object. This eliminates the need for creating and checking a separate variable.
Currently, in TypeScript, we achieve something like this:
const foo = getFoo();
if(foo)
{
console.log("Got the foo, and here is it's bar: " + foo.bar);
}
else {
console.log("Can't get the foo!");
}