Custom code regions in TypeScript
To enable custom code regions for TypeScript SDKs, update the project’s
.speakeasy/gen.yaml
file as follows:
Full example
The Speakeasy examples repository includes a full TypeScript SDK
Regions
Below are the available code regions in TypeScript SDKs.
SDK classes
TypeScript SDK classes can have two code regions:
// #region imports
: The imports region allows you to add imports to an SDK file needed for custom methods and properties. It must be located at the top of the file alongside generated imports.// #region sdk-class-body
: The class-body region allows you to add custom methods and properties to an SDK class. It must be located in the body of a TypeScript SDK class alongside generated methods and properties.
Managing dependencies
When adding custom code that requires external packages, configure these dependencies in the .speakeasy/gen.yaml
file to prevent them from being removed during SDK regeneration. Use the additionalDependencies
configuration to specify package dependencies:
This ensures that dependencies persist across SDK regenerations and are properly included in the generated package.json
.
Last updated on