Search code examples
c#typescriptdtotypelite

TypeLite: How to convert IEnumerable<T> to any[]


Let's say I have the following C# class:

[TsClass]
public class Results<T>
{
    public IEnumerable<T> Values { get; set; }
}

I would like typelite to generate the following interface:

interface IResults {
    values: any[];
}

(I am appending an 'I' to the class name and lowercasing the class properties, and that works fine.)

Typelite is currently converting IEnumerable<T> to IT, which I obviously don't want. The I is being appended and the T is the generic type.

interface IResults {
    values: IT[];
}

I've looked at the following SO question which points to WithConverter or WithFormatter. Typelite: Why is Dictionary<string, object> mapped to KeyValuePair and not to any or [index:string]:any I also looked at the typelite docs, but they don't have examples, so I'm feeling stuck. http://type.litesolutions.net/doc

Any help would be appreciated!


Solution

  • I did get this to work, but it's definitely a hack. Funny I didn't think of it sooner.

    <#= ts.Generate(TsGeneratorOutput.Properties).Replace("IT[]", "any[]" ) #>