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
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.
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.
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.
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.
- Angular sample .NET 6
- Base class annotated with JsonDerivedType (for generator purposes discriminators are mixed string, number and nameof - which is string - normally you should use one convention) ComplexBaseModel.cs
- TypeScript autogenerated version ComplexBaseModel.ts
- Derived class ComplexAModel.cs
- TypeScript autogenerated version ComplexAModel.ts
- code for generating models
- sample contains also enum and records generation
- Angular also contains automatic generation of service classes from controllers - by using code for generating services
- 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
To show new functionality with polymorphism https://devblogs.microsoft.com/dotnet/system-text-json-in-dotnet-7/#using-type-discriminators Please see in samples:
- Angular sample .NET 7
- Base class annotated with JsonDerivedType (for generator purposes discriminators are mixed string, number and nameof - which is string - normally you should use one convention) ComplexBaseModel.cs
- TypeScript autogenerated version ComplexBaseModel.ts
- Derived class ComplexAModel.cs
- TypeScript autogenerated version ComplexAModel.ts
- code for generating models
- sample contains also enum and records generation
- Angular also contains automatic generation of service classes from controllers - by using code for generating services
- 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
- added AssemblyName to symbols to be able to use type containing assembly name in templates
- version compatible with Visual Studio 17.8.0
- removing BOM in generated files
- added IsDictionary and IsDynamic boolean value to Type
- fix in Guid empty representation in TypeScript
- added option flag DisableStrictNullGeneration to disable generation of strict null checks in TypeScript
- Fixed IsDate property for nullable DateTime and DateTimeOffset thanks to @ArtemDintecom
- fixed regression with encodeUriComponent
- AdaskoTheBeAsT/Typewriter#22 closed
- Added single file mode thanks to @nfMalde PR 20
- upgraded libs
- upgraded obsoleted code to [IAsyncQuickInfoSourceProvider]
- version compatible with Visual Studio 17.4.0
- updated readme
- Compatible with Visual Studio 17.3.3
- Compatible with Visual Studio 17.3.2
- version compatible with Visual Studio 17.3.x
- added special fork of Buildalyzer to be able to run tests - existing version of Buildalyzer compatible with net 4.7.2 too old and causing problems with tests
- fixed tool manifest dependency to require VS 17.2.x
- version compatible with Visual Studio 17.2.x
- latest updates for Visual Studio 17.1.x
- fix relative paths in output directory - now relative to template location
- ability to setup different output directory in settings.OutputDirectory
- ability to skip adding generated files in project in template by using settings.SkipAddingGeneratedFilesToProject
- file scoped namespaces C# 10 compatibility
- exposing solution path in settings
- compatible with Visual Studio 2022
- IsNullable support for C# 8 nullable reference types RudeySH
- added DefaultValue
- PR 306 fix typo Shamus03
- PR 313 Ignores the Assembler if versions are equals. augustinbcu01
- PR 328 Url parameters of type DateTime[Offset] should be urlencoded rodro75
- PR 329 Added IsVirtual to Property metadata Ackhuman
- Added support for C# 9.0 records
- Fixed error for 'string?' type - invalid marked as IsEnumerable