Nuclear Potato Monster

    csharp-models-to-typescript

    0.21.1 • Public • Published

    C# models to TypeScript

    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 csharp-models-to-typescript
    

    How to use

    1. Add a config file to your project that contains for example...
    {
        "include": [
            "./models/**/*.cs",
            "./enums/**/*.cs"
        ],
        "exclude": [
            "./models/foo/bar.cs"
        ],
        "namespace": "Api",
        "output": "./api.d.ts",
        "camelCase": false,
        "camelCaseEnums": false,
        "camelCaseOptions": {
            "pascalCase": false,
            "preserveConsecutiveUppercase": false,
            "locale": "en-US"
        },
        "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": "csharp-models-to-typescript --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 © Jonathan Svenheden

    Keywords

    none

    Install

    npm i csharp-models-to-typescript

    DownloadsWeekly Downloads

    764

    Version

    0.21.1

    License

    MIT

    Unpacked Size

    25.6 kB

    Total Files

    10

    Last publish

    Collaborators

    • jonathanp