Differences between C# code and TypeScript transpiled code
There are different behaviors between the C# code and the transpiled TypeScript code.
Depending on the case:
- We make an evolution so that the behavior of the transpiled TypeScript code is the same as the C# code.
- We do nothing because it has little added value and is too complex or it may cause performance issues.
On this page, you will find the cases of the second scenario. It will be updated as we encounter cases.
Null string interpolation
For the following C# code:
int? value = null;
string message = $"The value is {value}";
The transpiled TypeScript code is :
let value: number | null = null
let message: string = `The value is ${value}`
In C#, the "message" variable has the value "The value is ".
In TypeScript, the variable "message" has the value "The value is null".
Nullable numeric value parsing
In C#, the following parsing code produces an exception.
string? valueToParse = null;
decimal result = decimal.Parse(valueToParse);
return result;
However, when transpiled in TypeScript, this code will not throw and will return NaN.
When parsing values, it is recommended to check the result using the double.IsNan() method. You can use this method whether the C# value to check is a double, an int, a decimal or any other number type as they are all transpiled to the same number type in TypeScript.
string? valueToParse = null;
decimal result = decimal.Parse(valueToParse);
if (double.IsNaN((double)result))
{
// Handle error case
}
return result;
Known unsupported C# syntaxes
The following list is not exhaustive.