Duplicate TypeScript interfaces created for generic parameters

Issue #42 closed
Simon Lovely
created an issue

If an object contains multiple generic properties, with different generic parameter types, duplicate TypeScript definitions are created. For example:

(c#) [TsClass] public class GenericPropertiesBug { public KeyValuePair<string, string> Test1 { get; set; } public KeyValuePair<string, int> Test2 { get; set; } }

This will generate the following TypeScript:

interface GenericPropertiesBug {
  Test1: System.Collections.Generic.KeyValuePair;
  Test2: System.Collections.Generic.KeyValuePair;
}
}
declare module System.Collections.Generic {
interface KeyValuePair {
  Key: any;
  Value: any;
}
interface KeyValuePair {
  Key: any;
  Value: any;
}
}

... which contains two definitions for KeyValuePair. I can see this occurs as the code in TsModelBuild.Add() (line 73) checks to see if the type is already in the model, but as the type is different if the generic args are different I think the line should get the open-generic type instead:

if (!this.Classes.ContainsKey(clrType.IsGenericType ? clr.GetGenericTypeDefinition() : clrType)) {  // ....

I would be happy to submit a pull request if you want, although it probably won't be for a week or so.

Thanks for a really useful library! Simon.

Comments (5)

  1. Log in to comment