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
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
VisitModel method create a new TsClass model that represents angular model interfaceVisitClass method set BaseType to the class created in VisitModel method for every classcall 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With