Would you believe I have a plethora of .Net libraries/classes that I want to create typescript definitions for? Typescript is truly amazing! I experimented with simple examples and it worked flawlessly. However, the hiccup I'm facing now is that a particular combination doesn't seem to cooperate. Here's the issue at hand:
[TsClass]
public class Bob<T>
{
public MyTestEnum MyEnum { get; set; }
public string TestString { get; set; }
public string MyProperty { get; set; }
}
[TsEnum]
public enum MyTestEnum
{
One,
Two,
Three
}
The crux of the problem lies in the fact that I can't seem to use both generics <T>
and Enum
together. It seems one has to be sacrificed for the other to work.
Whenever I attempt to run it, this pesky error pops up:
Error 17 Running transformation: System.NullReferenceException: Object reference not set to an instance of an object.
at TypeLite.TsModelBuilder.AddEnum(TsEnum tsEnum) in C:\___PROJECTS___\TypeLITE\TypeLite\TsModelBuilder.cs:line 98
at TypeLite.TsModelBuilder.Add(Type clrType, Boolean includeReferences) in C:\___PROJECTS___\TypeLITE\TypeLite\TsModelBuilder.cs:line 83
at TypeLite.TsModelBuilder.Add(Assembly assembly) in C:\___PROJECTS___\TypeLITE\TypeLite\TsModelBuilder.cs:line 108
at TypeLite.Net4.TypeScriptFluentExtensions.ForLoadedAssemblies(TypeScriptFluent ts) in C:\___PROJECTS___\TypeLITE\TypeLite.Net4\TypeScriptFluentExtensions.cs:line 16
at Microsoft.VisualStudio.TextTemplatingBDE10CD05B2CB4C5419DB79DDF5BA5BA06D673F55FF952439E5971D4E1F394085E3B6D99DC6D1E992221FAC06D0692FFD83BE54FE5AF6A567A491DF31AE26472.GeneratedTextTransformation.TransformText() ..\Scripts\TypeLite.Net4.tt
The issue isn't really about using generics per se (I just want it to work!).
If anyone knows how to navigate around this or can suggest an alternative tool that can handle such scenarios, please do share your insights.
I've already brought this to the attention of the developers (fingers crossed Lukas addresses it soon): https://bitbucket.org/LukasKabrt/typelite/issue/41/issue-with-generics-and-enums