I have a project where I am converting Scala code to TypeScript.
In Scala, there is a predefined type called Option which can either be a specific type or undefined.
In TypeScript, we usually represent it like this:
var myVar : MyType | undefined = await methodCall(...)
The methodCall function may look something like this:
function methodCall(...) : Promise<MyType | undefined>
{
........
// The function body
}
Now, I am trying to find a way in TypeScript to define a type similar to Scala's Options, for example:
Problem Statement:
MyTypeOption ... it can be of MyType or undefined
Any suggestions on how I can achieve this in TypeScript?
Currently, my TypeScript code looks like this:
var myVar : MyType | undefined = await methodCall(...)
function methodCall(...) : Promise<MyType | undefined>
{
........
// The function body
}