ts-from-csmodels

This is a tool that consumes your C# domain models and types and creates TypeScript declaration files from them. There's other tools that does this but what makes this one different is that it internally uses Roslyn (the .NET compiler platform) to parse the source files, which removes the need to create and maintain our own parser.

Usage no npm install needed!

<script type="module">
  import tsFromCsmodels from 'https://cdn.skypack.dev/ts-from-csmodels';
</script>

README

Generate Typescript form C# models

This is a tool that consumes your C# domain models and types and creates TypeScript declaration files from them. There's other tools that does this but what makes this one different is that it internally uses Roslyn (the .NET compiler platform) to parse the source files, which removes the need to create and maintain our own parser.

NPM version

Dependencies

Install

$ npm install --save ts-from-csmodels

How to use

  1. Add a config file to your project that contains for example...
{
    "include": {
  
      "./src/output-directory": [ 
        "../../another-csharp-models/first/**/*.cs",
        "../../another-csharp-models/second/models.ts"
       ],
      "./src/another-output-directory": [ 
        "../../another-csharp-models/another/**/*.cs",
      ]  
  
    },
    "camelCase": false,
    "camelCaseEnums": false,
    "numericEnums": false,
    "stringLiteralTypesInsteadOfEnums": false,
    "customTypeTranslations": {
      "ProductName": "string",
      "ProductNumber": "string"
    }
  }
  1. Add a npm script to your package.json that references your config file...
"scripts": {
    "generate-types": "ts-from-csmodels --config=your-config-file.json"
},
  1. Run the npm script generate-types and the output file specified in your config should be created and populated with your models.

License

MIT © Saeed Rahimi