Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typelite POCO Class Generation

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
};
like image 657
bingles Avatar asked Oct 07 '14 14:10

bingles


2 Answers

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") #>
like image 117
Flores Avatar answered Oct 05 '22 04:10

Flores


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;
    }
}
like image 39
Pavel B. Novikov Avatar answered Oct 05 '22 03:10

Pavel B. Novikov