MateusTech.ModelGenerator.Typescript 1.0.0-alpha

This is a prerelease version of MateusTech.ModelGenerator.Typescript.
dotnet add package MateusTech.ModelGenerator.Typescript --version 1.0.0-alpha
                    
NuGet\Install-Package MateusTech.ModelGenerator.Typescript -Version 1.0.0-alpha
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MateusTech.ModelGenerator.Typescript" Version="1.0.0-alpha" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MateusTech.ModelGenerator.Typescript" Version="1.0.0-alpha" />
                    
Directory.Packages.props
<PackageReference Include="MateusTech.ModelGenerator.Typescript" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MateusTech.ModelGenerator.Typescript --version 1.0.0-alpha
                    
#r "nuget: MateusTech.ModelGenerator.Typescript, 1.0.0-alpha"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MateusTech.ModelGenerator.Typescript@1.0.0-alpha
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MateusTech.ModelGenerator.Typescript&version=1.0.0-alpha&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=MateusTech.ModelGenerator.Typescript&version=1.0.0-alpha&prerelease
                    
Install as a Cake Tool

Model Generator

This library aims to generate Typescript interfaces from many programming languages.

In the backend development it is very common to create DTOs (Data Transfer Objects) to represent the data that is being sent or received by the API. It is also very common to have models that generate database migrations. This library generates Typescript interfaces for frontend (whether it is to be used in React, Angular, or any other web frameworks) from the backend.

Usage

 // Import statements
 // ...
namespace ExampleUsage;
 
class Program
{
    private static DirectoryInfo? TryGetSolutionDirectoryInfo(string? currentPath = null)
    {
        var directory = new DirectoryInfo(
            currentPath ?? Directory.GetCurrentDirectory()
        );
        while (directory != null && !directory.GetFiles("*.sln").Any())
        {
            directory = directory.Parent;
        }

        return directory;
    }

    public static void Main()
    {
        var directory = TryGetSolutionDirectoryInfo();
        if (directory != null)
        {
            var typescriptOutPath = $"{directory}/ExampleUsage/Out";
            var csharpModelsPaths = new List<string>
            {
                $"{directory}/ExampleUsage/Models"
            };
            var outSubFolders = new List<string>
            {
                "addresses",
                "products",
                "orders",
                "payments",
                "customers",
                "categories",
            };

            var convertModels = new ConvertModels(
                typescriptOutPath: typescriptOutPath,
                csharpModelsPaths: csharpModelsPaths,
                outSubFolders: outSubFolders
            );
            convertModels.GenerateTypeScriptInterfaces();
        }
    }
}

To get started, you must provide the paths to the C# models and the path where the Typescript interfaces will be generated. The outSubFolders parameter is optional and it is used to aggregate the interfaces in subfolders. We have a base class called ConvertModels and at this class we have exposed methods to convert to either interfaces, types or classes in typescript. You can also find this example at ExampleUsage C# project.

Contributing

If you want to contribute to this project, please read the CONTRIBUTING.md file.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0-alpha 192 3/13/2025

Initial alpha release.