Overview
The SDK includes:- Full TypeScript source code
- Exported type definitions for all interfaces
- Strict type checking enabled
- IDE autocomplete support
- Discriminated unions for type safety
Requirements
- TypeScript 5.9.3 or higher (recommended)
- Node.js 20.15.0 or higher
- ESM or CommonJS module support
Installation
Types are included automatically when you install the SDK:@types package is needed.
Configuration
Recommended tsconfig.json
The SDK is built with strict type checking. We recommend similar settings:tsconfig.json
ESM vs CommonJS
The SDK supports both module systems with proper type definitions.Type Definitions
Core Types
The SDK exports all core types for use in your application.Interface Examples
User Interface
Organization Interface
Directory User Interface
Options Types
All SDK methods accept typed options objects.List Response Types
Paginated list responses use a genericList type.
Type-Safe Client Modes
Discriminated Client Types
UsecreateWorkOS() for compile-time type safety based on client mode.
Type Guards
The SDK uses TypeScript discriminated unions for type safety.Generic Types
Webhook Events
Webhook events use discriminated unions based on event type.Custom Metadata
Metadata fields use generic Record types.IDE Support
Autocomplete
The SDK provides full autocomplete in modern IDEs:JSDoc Documentation
All methods include JSDoc comments for inline documentation:Type Imports
Useimport type for type-only imports (recommended for better tree-shaking):
Runtime Types
Cloudflare Workers
Use the/worker export for edge runtime types:
Deno
Deno works with standard TypeScript imports:Type Checking
Compiler Settings
The SDK is built with these strict compiler options:Type Checking Commands
Check types without emitting files:Common Patterns
Async/Await with Types
Error Handling with Types
Type Narrowing
Best Practices
Use Type Imports
Prefer
import type for type-only imports to improve tree-shaking and build performance.Enable Strict Mode
Use
strict: true in tsconfig.json for better type safety and error detection.Define Custom Types
Extend SDK types with your own interfaces for domain-specific metadata and fields.
Type Guards
Use type guards and discriminated unions for safer runtime type checking.
Resources
Need Help?
Having TypeScript issues?- Check the GitHub repository for examples
- Open an issue for type definition bugs
- Contact [email protected]