Generic classes result in invalid interface definitions

Issue #5 resolved
created an issue

I have a generic c# class that looks like this:

    public class StatisticDto<KeyType,ValueType>
        public KeyType Key { get; set; }
        public ValueType Value { get; set; }

TypeLite outputs this (which is invalid Typescript code):

interface StatisticDto`2 {
  Key: KeyType;
  Value: ValueType;

Note the "`2" on the classname. This is because the reflection methods you are using return that for the generic class. One might assume that this means we shouldn't transform generic classes, but if you consider that Ajax will strip away any generic definitions also, it makes more sense to me for you to ignore the generic definition and simply set the Key and Value properties to a type of "any". This will maintain the interface structure and provide something useful beyond "any";

As it stands, the TypeLite library produces invalid TypeScript code when attempting to transform a generic class.

Comments (2)

  1. Lukas Kabrt repo owner

    I updated code as you suggested, it's probably the best solution for now. Fix will be included in the next release (0.8.3)

    Version 0.9 of the TypeScript will support generic types and I am planing to add support for them to TypeLite as well, so the current behaviour might change in the future.

  2. Log in to comment