AdaskoTheBeAsT / Typewriter

Automatic TypeScript template generation from C# source files
http://frhagn.github.io/Typewriter
Apache License 2.0
66 stars 13 forks source link

Typewriter (Unofficial fork)

Typewriter is a Visual Studio extensions that generates TypeScript files from c# code files using TypeScript Templates. This allows you to create fully typed TypeScript representations of server side API, models, controllers, SignalR hubs etc. that automatically updates when you make changes to your c# code.

Original Documentation
Download Last Unofficial Version

Why new fork?

It seems that Fredrik Hagnelius author of Typewriter is very busy and do not have enough time for supporting that extensions. From the other side that extensions really helps fullstack developers and work on it should be continued.

Issues

The issue tracker is the preferred channel for bug reports, features requests and submitting pull requests.
For personal support requests Stack Overflow is a better place to get help. Please use the typewriter tag when posting your questions.

Getting started

Step 1: Add a TypeScript Template file (.tst)
Step 2: Add the following code in the template

$Classes(*Model)[ // Find all classes with a name ending with Model
    class $Name {
        constructor($Properties[public $name: $Type][, ]) {
        }
    }
]

Step 3: Save the template
Step 4: Add a c# class named TestModel
Step 5: Add the following code to the class

using System;

namespace TestApplication
{
    public class TestModel
    {
        public int Id { get; set; }
        public int Name { get; set; }
    }
}

Step 6: Save the class.

Each time a class matching the filter in the template is saved a TypeScript class matching the template is updated or added to the project.

Advanced usage of templates

Repository https://github.com/AdaskoTheBeAsT/NetCoreTypewriterRecipes shows advanced generation of classes, interfaces, enums, records, etc. using Typewriter. It uses polymorphic capabilities of Newtonsoft.Json to properly generate TypeScript classes with polymorphiysm enabled - by using $type property. It also contains brand new generation of classes using System.Text.Json with polymorphic capabilities upcoming in .NET 7.

.NET 6 Newtonsoft.Json

  1. Angular sample .NET 6
  1. React sample .NET 6
    • use same ideas as in Angular sample - it is only limited to models due to multitude of possible creation api connecting functions ReactWebApiSample2

.NET 7 System.Text.Json

To show new functionality with polymorphism https://devblogs.microsoft.com/dotnet/system-text-json-in-dotnet-7/#using-type-discriminators Please see in samples:

  1. Angular sample .NET 7
  1. React sample .NET 7
    • use same ideas as in Angular sample - it is only limited to models due to multitude of possible creation api connecting functions ReactWebApiSample2

Main differences between original and this fork

Version 2.19.0

Version 2.18.0

Version 2.17.0

Version 2.16.0

Version 2.15.0

Version 2.14.0

Version 2.13.0

Version 2.12.1

Version 2.12.0

Version 2.11.0

Version 2.10.1

Version 2.10.0

Version 2.9.2

Version 2.9.1

Version 2.9.0

Version 2.8.1

Version 2.8.0

Version 2.7.0

Version 2.6.1

Version 2.6.0

Version 2.5.0

Version 2.3.1

Version 2.2.6

Version 1.32.0

Version 1.31.0

Version 1.30.0