Skip to content
Pavel Vostretsov edited this page May 9, 2023 · 2 revisions

Welcome to the TypeScript.ContractGenerator wiki!

How to Use

First, define types that need type generation:

public class FirstType
{
    public string StringProp { get; set; }
    public int IntProp { get; set; }
}

public class SecondType
{
    public string[] StringArray { get; set; }
    public FirstType FirstTypeProp { get; set; }
}

Then generate TypeScript files with:

var generator = new TypeScriptGenerator(TypeScriptGenerationOptions.Default, CustomTypeGenerator.Null, new RootTypesProvider(typeof(SecondType)));
generator.GenerateFiles("./output");

By default, this will generate file with name .ts with following content:

// tslint:disable
// TypeScriptContractGenerator's generated content

export type SecondType = {
    stringArray?: null | string[];
    firstTypeProp?: null | FirstType;
};
export type FirstType = {
    stringProp?: null | string;
    intProp: number;
};

If you want generated files to have different name or to generate some typings differently, you should pass your own implementation of ICustomTypeGenerator to TypeScriptGenerator.

Clone this wiki locally