Typescript Configuration Options
This section details the available configuration options for the TypeScript SDK. All configuration is managed in the gen.yaml file under the typescript section.
Version and general configuration
typescript:
version: 1.2.3
author: "Author Name"
packageName: "custom-sdk"Additional JSON package
typescript:
additionalPackageJSON:
license: "MIT"Additional dependencies
typescript:
additionalDependencies:
dependencies:
axios: "^0.21.0"
devDependencies:
typescript: "^4.0.0"
peerDependencies:
react: "^16.0.0"Package scripts and examples
typescript:
additionalScripts:
format: "prettier --write src"
docs: "typedoc --out docs src"
custom-test: "vitest run --coverage"
generateExamples: true
compileCommand: ["npm", "run", "build"]
usageSDKInit: "new Petstore({})"
usageSDKInitImports:
- package: "@petstore/sdk"
import: "Petstore"
type: "packageImport"How scripts are merged
The feature uses an override strategy where additional scripts take precedence over default scripts:
- Default scripts are generated automatically based on SDK configuration:
{
"lint": "eslint --cache --max-warnings=0 src",
"build": "tsc",
"prepublishOnly": "npm run build"
}- Test scripts are added if tests are enabled:
{
"test": "vitest run src --reporter=junit --outputFile=.speakeasy/reports/tests.xml --reporter=default",
"check": "npm run test && npm run lint"
}- Additional scripts override defaults if they have the same name:
typescript:
additionalScripts:
build: "custom-build-command" # Replaces default "tsc" build
deploy: "npm publish" # Adds new script- Result in
package.json:
{
"scripts": {
"build": "custom-build-command", // Overridden
"check": "npm run test && npm run lint",
"deploy": "npm publish", // Added
"lint": "eslint --cache --max-warnings=0 src",
"prepublishOnly": "npm run build",
"test": "vitest run src --reporter=junit --outputFile=.speakeasy/reports/tests.xml --reporter=default"
}
}Method and parameter management
typescript:
maxMethodParams: 3
flatteningOrder: "parameters-first"
methodArguments: "infer-optional-args"Security configuration
typescript:
envVarPrefix: SPEAKEASY
flattenGlobalSecurity: trueModule management
typescript:
moduleFormat: "dual"
useIndexModules: true
legacyFileNaming: falsePerformance optimization
For optimal bundle size and tree-shaking performance in modern applications, consider using moduleFormat: "esm" together with useIndexModules: false. This combination provides the best possible bundler optimizations. Use dual if CommonJS compatibility is required.
Import management
typescript:
imports:
option: "openapi"
paths:
callbacks: models/callbacks
errors: models/errors
operations: models/operations
shared: models/components
webhooks: models/webhooksImport paths
Error and response handling
typescript:
clientServerStatusCodesAsErrors: true
responseFormat: "flat"
enumFormat: "union"
defaultErrorName: "SDKError"
baseErrorName: "HTTPError"
acceptHeaderEnum: falseModel validation and serialization
typescript:
jsonpath: "rfc9535"
zodVersion: "v4-mini"
constFieldsAlwaysOptional: false
modelPropertyCasing: "camel"
unionStrategy: "populated-fields"
laxMode: "lax"
alwaysIncludeInboundAndOutbound: false
exportZodModelNamespace: falseForward compatibility
These options control how the SDK handles API evolution, allowing older SDK versions to continue working when APIs add new enum values, union types, or fields.
typescript:
forwardCompatibleEnumsByDefault: true
forwardCompatibleUnionsByDefault: tagged-onlyForward compatibility and fault tolerance
These options work together with laxMode and unionStrategy to provide robust forward compatibility. When all four features are enabled (the default for new TypeScript SDKs), your SDK will gracefully handle API evolution including new enum values, new union types, missing fields, and type mismatches. See the forward compatibility guide for more details.
Server-sent events configuration
typescript:
sseFlatResponse: falseBuild toolchain
These options update the TypeScript SDK build toolchain to use faster, modern build tools. Enabling both options can speed up generation time by up to 35% in GitHub Actions and locally.
typescript:
useOxlint: true
useTsgo: trueGeneration speed optimization
For fastest generation times, enable both useOxlint and useTsgo together. OxLint replaces ESLint with a Rust-based linter that processes files in parallel, while TSGo replaces tsc with a native Go compiler that delivers up to 10x faster type checking. Combined, these tools can reduce SDK generation time by up to 35%.
Advanced features
typescript:
enableReactQuery: false
enableMCPServer: falseLast updated on