Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeLite generation with adding hirarchal dependency

I'm currently using a Client build with AngularJS 1.x in TypeScript and an AspNet WebApi Backend in C#.

For communication with the backend I use the $resource-Service from angular. By using this service, my model interfaces generated with TypeLITE have to extend

ng.resource.IResource<IModel> 

Is it possible to automatically extend all generated model interfaces from this interface described by angular?

Otherwise all has to be done separatly like this

export interface Model extends ng.resource.IResource<Model> {
}

Many thanks in advance, MacX

like image 540
MacX Avatar asked Jan 19 '26 02:01

MacX


1 Answers

This isn't a straightforward task. An option is to create a custom TsModelVisitor that adds dummy class ng.resource.IResource<T> to the code model and modifies base class for all other classes in the code model.

I would try following steps:

  • create a class that derives from TsModelVisitor

    • in VisitModel method create a new TsClass model that represents angular model interface
    • in VisitClass method set BaseType to the class created in VisitModel method for every class
  • call your model visitor in .tt file

    var ts = TypeScript.Definitions()
                 .AsConstEnums(false);
    var model = ts.ModelBuilder.Build();
    model.RunVisitor(new YourModelVisitor());
    
  • instead of <#= ts.Generate(TsGeneratorOutput.Properties) #> use '<#= ts.ScriptGenerator.Generate(model, TsGeneratorOutput.Properties) #>' to generate output

like image 86
Lukas Kabrt Avatar answered Jan 21 '26 14:01

Lukas Kabrt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!