Skip to content
FeedbackDashboard
Codegen targets

TypeScript

Generate production-ready TypeScript SDKs from your OpenAPI specification

The Stainless TypeScript SDK generator creates idiomatic, type-safe TypeScript client libraries from your OpenAPI specification. The TypeScript target uses built-in fetch for HTTP requests, making SDKs dependency-free by default.

Example repositories:

To generate a TypeScript SDK, add the typescript target to your Stainless configuration file:

targets:
typescript:
package_name: my-company-sdk
edition: typescript.2025-10-10
targets:
typescript:
package_name: my-company-sdk
# Specify the edition
edition: typescript.2025-10-10
# Specify the package manager (default: pnpm)
package_manager: pnpm # or: yarn, npm
# Configure publishing
publish:
npm: true
jsr:
package_name: "@my-scope/my-sdk"

For a complete list of configuration options, see the TypeScript target reference.

Editions allow Stainless to make improvements to SDKs that are not backwards-compatible. You can explicitly opt in to new editions when you are ready. See the SDK and config editions reference for more information.

  • Changed default package manager from yarn to pnpm
  • To revert to yarn, set options.package_manager: yarn
  • Initial edition for TypeScript (used by default if no edition is specified)

TypeScript SDKs use native fetch and work across multiple JavaScript runtimes. The SDK automatically detects the runtime environment and configures itself accordingly.

EnvironmentStatusNotes
Node.js 18+ LTSFull supportRecommended: Node 20+ for TypeScript projects
Deno 1.28+Full supportUses web runtime natively
Bun 1.0+Full supportCompatible with Node.js APIs
Cloudflare WorkersFull supportTested in ecosystem tests
Vercel Edge RuntimeFull supportUses web-compatible APIs
Nitro 2.6+Full supportEarlier versions had exports map issues
Web browsersConditionalChrome, Firefox, Safari, Edge (requires configuration)
React NativeWith polyfillsRequires polyfills for streaming support
Jest 28+Node environment onlyjsdom environment not supported

By default, most SDKs block browser usage to prevent accidental API key exposure. You can configure browser support in your Stainless config:

targets:
typescript:
options:
browser:
state: allow # or: disallow, dangerous_allow
ModeBehavior
allowSDK works in browsers without restrictions
disallowThrows an error if used in a browser (default for most SDKs)
dangerous_allowRequires explicit dangerouslyAllowBrowser: true in client options

Ensure your tsconfig.json meets the minimum requirements:

{
"compilerOptions": {
"target": "ES2015",
"lib": ["ES2018"],
"moduleResolution": "bundler"
}
}

Minimum requirements:

  • target: ES2015 or higher (required for WeakMap and private class fields)
  • lib: ES2018 or higher (required for AsyncIterable)
  • moduleResolution: bundler (recommended for TS 5.0+) or NodeNext

Environment-specific types:

Depending on your runtime, include the appropriate type definitions:

RuntimeTypes configuration
Node.js@types/node >= 18.18.7
Bun@types/bun >= 1.2.0
Cloudflare Workers@cloudflare/workers-types with lib: ["ES2020"]
Browserslib: ["DOM", "DOM.Iterable", "ES2018"]
DenoNo additional configuration needed

Package your TypeScript SDK for distribution on npm, making it easy for users to install with npm install.

Publish your package to npm for the first time

Before you can configure trusted publishing, npm requires that your package already exists. Follow these steps to publish your SDK manually for the first time:

  1. Clone your SDK’s production repository and navigate to it.

  2. Install dependencies and build the SDK:

    Terminal window
    pnpm install
    pnpm build
  3. Navigate to the dist directory where the publishable package is located:

    Terminal window
    cd dist
  4. Log in to npm:

    Terminal window
    npm login

    This opens a browser window to complete the npm OAuth flow. Follow the prompts to authenticate.

  5. Publish the package:

    Terminal window
    pnpm publish

After your package is published, you can proceed to configure trusted publishing.

Setup GitHub Actions as a trusted publisher
  1. Navigate to your packages settings at npmjs.com/package/<package-name>/access and under the Trusted Publisher section choose GitHub Actions.

  2. Fill in the organization or user where your SDK’s repository lives and the repository’s name.

  3. Put in publish-npm.yml as the workflow filename.

  4. [Recommended] If you use a specific GitHub Actions environment for releases, specify it for environment name. This restricts publishing to release workflows running in that environment.

    To set the release environment, add it to your Stainless config:

    codeflow:
    release_environment: <environment-name>
    # ...
  5. Click Set up connection.

Update your Stainless config

Update the Stainless config to specify OIDC authentication and save.

targets:
typescript:
package_name: <package-name>
publish:
npm:
auth_method: oidc

Publish your TypeScript SDK to JSR for use with Deno and other JavaScript runtimes.

Create a JSR package
  1. Log in or sign up at JSR.
  2. Select Publish a package.
  3. Choose an appropriate scope and package name.
  4. Select Create.
Link your production repo and configure security
  1. In JSR, navigate to <package-name> > Settings > GitHub Repository.
  2. Link the production repo to the JSR package you created.
  3. Navigate to your <scope-name> > Settings > GitHub Actions security.
  4. Select Do not restrict publishing. This allows the Stainless GitHub App to publish even though it is not a member of your scope.
Update your Stainless config

Update the Stainless config with your package name and save.

targets:
typescript:
publish:
jsr:
package_name: "@<scope-name>/<package-name>"

React Native does not include all web APIs that the TypeScript SDK expects. To use a Stainless-generated TypeScript SDK in React Native, you need to install polyfills for the missing APIs.

For bare React Native projects (or Expo projects that need streaming), install the following polyfills:

Terminal window
npm install react-native-url-polyfill

Then import them at the top of your app entry point (before any SDK imports):

// App.tsx or index.js - import polyfills first
import 'react-native-url-polyfill/auto';
import { polyfillGlobal } from 'react-native/Libraries/Utilities/PolyfillFunctions';
import { fetch, Headers, Request, Response } from 'react-native-fetch-api';
// Polyfill fetch with streaming support
polyfillGlobal('fetch', () => fetch);
polyfillGlobal('Headers', () => Headers);
polyfillGlobal('Request', () => Request);
polyfillGlobal('Response', () => Response);
// Now import your SDK
import MySDK from 'my-sdk';

The TypeScript SDK requires these browser/Node.js APIs that React Native does not provide:

APIPolyfill package
URL / URLSearchParamsreact-native-url-polyfill
fetch / Headers / Request / Responsereact-native-fetch-api
crypto.getRandomValuesreact-native-get-random-values

Ensure your tsconfig.json includes DOM types:

{
"compilerOptions": {
"target": "ES2015",
"lib": ["DOM", "DOM.Iterable", "ES2018"]
}
}

For file uploads in React Native, use the SDK’s toFile helper with a Blob or the file’s URI:

import * as FileSystem from 'expo-file-system';
// Read file as base64 and convert to Blob
const base64 = await FileSystem.readAsStringAsync(fileUri, {
encoding: FileSystem.EncodingType.Base64,
});
const blob = await fetch(`data:application/octet-stream;base64,${base64}`).then(r => r.blob());
// Use with the SDK
const response = await client.files.upload({
file: await toFile(blob, 'filename.pdf'),
});
Migrate from the Node target to TypeScript

If you currently use the node target, you can migrate to the typescript target to benefit from zero dependencies and improved developer experience. The new TypeScript SDK generator uses built-in fetch instead of node-fetch.

For more information on the changes, see the changelog entry.

Custom code conflicts

To avoid problems during the migration, make sure your Node SDK does not have any open conflict PRs.

  1. Go to your project’s “Overview” page.
  2. If you see an open conflict, resolve it first. See our custom code documentation for more details.
Node SDK with custom code conflict
Example of a Node SDK with a custom code conflict

Production repositories

You will need to decide whether you want to reuse your Node SDK’s prod repo as-is, rename it (e.g. from my-node-sdk to my-typescript-sdk), or create a new repo (to make it easier to refer to the previous version’s source code).

  • If you want to keep the same prod repo and name, no action is needed and you can continue with the migration steps.
  • If you are reusing the existing prod repo but want to rename it (for example, from my-node-sdk to my-typescript-sdk), first complete the migration steps, then rename the GitHub repo and update the production_repo key in your Stainless config.
  • If you prefer to create a new production repo, do so before migrating.
  1. Note the current version of your node SDK from its package.json.

  2. Choose a new version number. This is a breaking change, so if you have released a v1 you need to bump the major version (for example, v1.x.x → v2.0.0).

  3. In your Stainless config, add a new typescript target:

    targets:
    node: # <-- Your existing node target
    package_name: my-sdk
    production_repo: my-org/my-sdk-node
    publish:
    npm: true
    typescript: # <-- The new typescript target
    package_name: my-sdk # Same name as for node
    production_repo: null # Don't set the prod repo yet
    publish:
    npm: false
    options:
    node_migration: # These values will be used in the generated migration guide
    previous_version: '1' # Last version number before migration
    migrated_version: '2' # New version number for the `typescript` SDK
  4. Save and build. Stainless creates a new staging repository named <project_name>-typescript.

  5. Review the MIGRATION.md file that Stainless generates in the TypeScript staging repo and verify that everything looks correct.

  6. Update the typescript target to use the prod repo, set the publish.npm flag to true, and remove the node target. If you prefer to keep the node target in your config, set its production_repo to null.

    targets:
    typescript:
    package_name: my-sdk
    production_repo: my-org/my-sdk-node # Updated prod repo
    publish:
    npm: true # Enabled NPM publishing
    options:
    node_migration:
    previous_version: '1'
    migrated_version: '2'
  7. Save and build. Stainless opens a release PR with the new typescript SDK and migration guide. If the version is not what you expected, update the PR title to correct it.

Your SDK is now using the typescript SDK generator, with zero dependencies and an improved developer experience.

If you have questions or run into issues, email us at support@stainless.com.