Packages
ash_typescript
0.6.0
0.17.3
0.17.2
0.17.1
0.17.0
0.16.0
0.15.3
0.15.2
retired
0.15.1
retired
0.15.0
0.14.4
0.14.3
0.14.2
0.14.1
0.14.0
retired
0.13.2
0.13.1
0.13.0
0.12.1
0.12.0
0.11.6
0.11.5
0.11.4
0.11.3
0.11.2
0.11.1
0.11.0
0.10.2
0.10.1
0.10.0
0.9.1
0.9.0
0.8.4
0.8.3
0.8.2
0.8.1
0.8.0
0.7.1
0.7.0
0.6.4
0.6.3
0.6.2
0.6.1
0.6.0
0.5.0
0.4.0
0.3.3
0.3.2
0.3.1
0.2.0
0.1.2
0.1.0
Generate type-safe TypeScript clients directly from your Ash resources and actions, ensuring end-to-end type safety between your backend and frontend.
Current section
Files
Jump to
Current section
Files
ash_typescript
README.md
README.md
<!--
SPDX-FileCopyrightText: 2025 Torkild G. Kjevik
SPDX-FileCopyrightText: 2025 ash_typescript contributors <https://github.com/ash-project/ash_typescript/graphs.contributors>
SPDX-License-Identifier: MIT
-->
<img src="https://github.com/ash-project/ash_typescript/blob/main/logos/ash-typescript.png?raw=true" alt="Logo" width="300"/>

[](https://opensource.org/licenses/MIT)
[](https://hex.pm/packages/ash_typescript)
[](https://hexdocs.pm/ash_typescript)
[](https://api.reuse.software/info/github.com/ash-project/ash_typescript)
# AshTypescript
**π₯ Automatic TypeScript type generation for Ash resources and actions**
Generate type-safe TypeScript clients directly from your Elixir Ash resources, ensuring end-to-end type safety between your backend and frontend. Never write API types manually again.
## β¨ Features
- **π₯ Zero-config TypeScript generation** - Automatically generates types from Ash resources
- **π‘οΈ End-to-end type safety** - Catch integration errors at compile time, not runtime
- **β‘ Smart field selection** - Request only needed fields with full type inference
- **π― RPC client generation** - Type-safe function calls for all action types
- **π‘ Phoenix Channel support** - Generate channel-based RPC functions for real-time applications
- **πͺ Lifecycle hooks** - Inject custom logic before/after requests (auth, logging, telemetry, error tracking)
- **π’ Multitenancy ready** - Automatic tenant parameter handling
- **π¦ Advanced type support** - Enums, unions, embedded resources, and calculations
- **π Action metadata support** - Attach and retrieve additional context with action results
- **π§ Highly configurable** - Custom endpoints, formatting, and output options
- **π§ͺ Runtime validation** - Zod schemas for runtime type checking and form validation
- **π Auto-generated filters** - Type-safe filtering with comprehensive operator support
- **π Form validation** - Client-side validation functions for all actions
- **π― Typed queries** - Pre-configured queries for SSR and optimized data fetching
- **π¨ Flexible field formatting** - Separate input/output formatters (camelCase, snake_case, etc.)
- **π Custom HTTP clients** - Support for custom fetch functions and request options (axios, interceptors, etc.)
- **π·οΈ Field/argument name mapping** - Map invalid TypeScript identifiers to valid names
## β‘ Quick Start
**Get up and running in under 5 minutes:**
```bash
# Basic installation
mix igniter.install ash_typescript
# Full-stack Phoenix + React setup
mix igniter.install ash_typescript --framework react
```
### 1. Add Resource Extension
```elixir
defmodule MyApp.Todo do
use Ash.Resource,
domain: MyApp.Domain,
extensions: [AshTypescript.Resource]
typescript do
type_name "Todo"
end
attributes do
uuid_primary_key :id
attribute :title, :string, allow_nil?: false
attribute :completed, :boolean, default: false
end
end
```
### 2. Configure Domain
```elixir
defmodule MyApp.Domain do
use Ash.Domain, extensions: [AshTypescript.Rpc]
typescript_rpc do
resource MyApp.Todo do
rpc_action :list_todos, :read
rpc_action :create_todo, :create
rpc_action :get_todo, :get
end
end
end
```
### 3. Generate Types & Use
```bash
mix ash.codegen --dev
```
```typescript
import { listTodos, createTodo } from './ash_rpc';
// β
Fully type-safe API calls
const todos = await listTodos({
fields: ["id", "title", "completed"],
filter: { completed: false }
});
const newTodo = await createTodo({
fields: ["id", "title", { user: ["name", "email"] }],
input: { title: "Learn AshTypescript", priority: "high" }
});
```
**π That's it!** Your TypeScript frontend now has compile-time type safety for your Elixir backend.
π **For complete setup instructions, see the [Getting Started Guide](documentation/tutorials/getting-started.md)**
## π Documentation
### Tutorials
- **[Getting Started](documentation/tutorials/getting-started.md)** - Complete installation and setup guide
- **[React Setup](documentation/tutorials/react-setup.md)** - Full Phoenix + React + TypeScript integration
### How-To Guides
- **[Basic CRUD Operations](documentation/how_to/basic-crud.md)** - Create, read, update, delete patterns
- **[Field Selection](documentation/how_to/field-selection.md)** - Advanced field selection and nested relationships
- **[Error Handling](documentation/how_to/error-handling.md)** - Comprehensive error handling strategies
- **[Custom Fetch Functions](documentation/how_to/custom-fetch.md)** - Using custom HTTP clients and request options
### Topics
- **[Lifecycle Hooks](documentation/topics/lifecycle-hooks.md)** - Inject custom logic (auth, logging, telemetry)
- **[Phoenix Channels](documentation/topics/phoenix-channels.md)** - Real-time WebSocket-based RPC actions
- **[Embedded Resources](documentation/topics/embedded-resources.md)** - Working with embedded data structures
- **[Union Types](documentation/topics/union-types.md)** - Type-safe union type handling
- **[Multitenancy](documentation/topics/multitenancy.md)** - Multi-tenant application support
- **[Action Metadata](documentation/topics/action-metadata.md)** - Attach and retrieve action metadata
- **[Form Validation](documentation/topics/form-validation.md)** - Client-side validation functions
- **[Zod Schemas](documentation/topics/zod-schemas.md)** - Runtime validation with Zod
### Reference
- **[Configuration](documentation/reference/configuration.md)** - Complete configuration options
- **[Mix Tasks](documentation/reference/mix-tasks.md)** - Available Mix tasks and commands
- **[Troubleshooting](documentation/reference/troubleshooting.md)** - Common issues and solutions
## ποΈ Core Concepts
AshTypescript bridges the gap between Elixir and TypeScript by automatically generating type-safe client code:
1. **Resource Definition** - Define Ash resources with attributes, relationships, and actions
2. **RPC Configuration** - Expose specific actions through your domain's RPC configuration
3. **Type Generation** - Run `mix ash.codegen` to generate TypeScript types and RPC functions
4. **Frontend Integration** - Import and use fully type-safe client functions in your TypeScript code
### Type Safety Benefits
- **Compile-time validation** - TypeScript compiler catches API misuse before runtime
- **Autocomplete support** - Full IntelliSense for all resource fields and actions
- **Refactoring safety** - Rename fields in Elixir, get TypeScript errors immediately
- **Living documentation** - Generated types serve as up-to-date API documentation
## π Example Repository
Check out the **[AshTypescript Demo](https://github.com/ChristianAlexander/ash_typescript_demo)** by Christian Alexander featuring:
- Complete Phoenix + React + TypeScript integration
- TanStack Query for data fetching
- TanStack Table for data display
- Best practices and patterns
## π Requirements
- Elixir 1.15 or later
- Ash 3.0 or later
- Phoenix (for RPC controller integration)
- Node.js 16+ (for TypeScript)
## π€ Contributing
Contributions are welcome! Please:
1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Make your changes with tests
4. Ensure all tests pass (`mix test`)
5. Run code formatter (`mix format`)
6. Commit your changes (`git commit -m 'Add amazing feature'`)
7. Push to the branch (`git push origin feature/amazing-feature`)
8. Open a Pull Request
Please ensure:
- All tests pass
- Code is formatted with `mix format`
- Documentation is updated for new features
- Commits follow conventional commit format
## π License
This project is licensed under the MIT License - see the [MIT.txt](LICENSES/MIT.txt) file for details.
## π Support
- **Documentation**: [https://hexdocs.pm/ash_typescript](https://hexdocs.pm/ash_typescript)
- **GitHub Issues**: [https://github.com/ash-project/ash_typescript/issues](https://github.com/ash-project/ash_typescript/issues)
- **Discord**: [Ash Framework Discord](https://discord.gg/HTHRaaVPUc)
- **Forum**: [Elixir Forum - Ash Framework](https://elixirforum.com/c/elixir-framework-forums/ash-framework-forum)
---