Is it possible for Typelite to generate a TypeScript class instead of an interface? Something like:
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
to
export class Person
{
constructor() {}
FirstName: string;
LastName: string;
}
I'm not looking for any functionality in the generated classes, only an easier way to be able to instantiate classes clientside without having to initialize the entire interface.
For example, I would prefer being able to do this:
var person = new Person();
Instead of
var person = {
FirstName: null,
LastName: null
};
What I did was make a simple adjustment to the tt file, saves you from compiling your own typelite:
<#= definitions.ToString()
.Replace("interface", "export class")
.Replace("declare module", "module") #>
This feature is supported by Reinforced.Typings.
Using attribute
[TsClass]
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
or fluent call
public class Configuration
{
public static void Configure(ConfigurationBuilder builder)
{
builder
.ExportAsClass<Person>()
.WithPublicProperties();
}
}
will produce following to the output file:
namespace MyApp {
export class User
{
public FirstName: string;
public LastName : string;
}
}
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