Netjs icon indicating copy to clipboard operation
Netjs copied to clipboard

Usage of Generics does not compile with tsc

Open kpfeuffer opened this issue 6 years ago • 2 comments

When compiling a C#-dll, in which Generics are used for accessing (for example) an object's properties, the tsc-Compiler throws an error for the generated ts-file.

In my case, this happened for using an Optional in C#, which looked like this

Optional<DateTime>.None

and looked like this in the ts-file

Optional<DateTime>.None

which couldn't be compiled by tsc.

It should compile to Option.None to work.

kpfeuffer avatar Dec 05 '18 10:12 kpfeuffer

I don't think Optional<T> is a type defined by .NET, which is why the expression remains as-is. The optional type is Nullable<T>.

From my experience, the transpiler can correctly handle nullable types by using the Nullable<T> class defined in mscorlib.ts; for example, float? is transpiled to Nullable<number>. This transformation is handled by MakeNullableExplicit.

westim avatar Dec 06 '18 02:12 westim

I'm sorry, but I guess I did not manage to get my point across correctly.

The Optional-Class in my case was defined in the dll itself, so this should not be the issue. What appears to be the problem is, that that usage of the generic class is not compiled correctly.

tsfile.ts:274:19 - error TS1005: '(' expected.

274 return Optional<T>._none;

So typescript seems to handle the syntax for using generics differently than C# does.

kpfeuffer avatar Dec 06 '18 06:12 kpfeuffer