Search code examples
c#typescriptreinforced-typings

How do I get Reinforced.Typings to generate "export interface" or "export enum" as output, without wrapping it in a module?


I'm using Reinforced.Typings to generate TypeScript models from my C# models. I want the models exported as the following, not wrapped in a module:

export interface IFoobar {
    someProperty: string;
    someOtherProperty: number;
}

export enum SomeEnum {
   someEnumValue = 0,
   someOtherEnumValue = 1
}

I am able to get it almost the way I want it by using the following configuration method:

public static void Configure(ConfigurationBuilder builder)
{
    builder.Global(config => config.CamelCaseForProperties()
                                   .AutoOptionalProperties());

    builder.ExportAsInterfaces(new [] { typeof(Foobar) },
                               config => config.WithPublicProperties()
                                               .AutoI()
                                               .DontIncludeToNamespace());

    builder.ExportAsEnums(new [] { typeof(SomeEnum) },
                          config => config.DontIncludeToNamespace());
}

This will create the following output, but the export keyword missing.

interface IFoobar {
    someProperty: string;
    someOtherProperty: number;
}

enum SomeEnum {
   someEnumValue = 0,
   someOtherEnumValue = 1
}

It is possible to achieve what I want? If possible I want to avoid attributes, and keep using the fluent API.


Solution

  • Try UseModules() in global config:

    builder.Global(config => config.CamelCaseForProperties()
                                   .AutoOptionalProperties()
                                   .UseModules());