-
Notifications
You must be signed in to change notification settings - Fork 24
Home
Pavel Vostretsov edited this page May 9, 2023
·
2 revisions
Welcome to the TypeScript.ContractGenerator wiki!
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
.