This document provides a comprehensive reference for all AshTypescript Mix tasks.
Automated installer that sets up everything you need to get started with AshTypescript.
# Basic installation (RPC setup only)
mix igniter.install ash_typescript
# Full-stack React + TypeScript setup
mix igniter.install ash_typescript --framework reactThe installer performs the following tasks:
-
Dependency Setup
- Adds AshTypescript to your
mix.exsdependencies - Runs
mix deps.getto install the package
- Adds AshTypescript to your
-
Configuration
- Configures AshTypescript settings in
config/config.exs - Sets default output paths and RPC endpoints
- Configures AshTypescript settings in
-
RPC Controller
- Creates RPC controller at
lib/*_web/controllers/ash_typescript_rpc_controller.ex - Implements handlers for run and validate endpoints
- Creates RPC controller at
-
Phoenix Router
- Adds RPC routes to your Phoenix router
- Configures
/rpc/runand/rpc/validateendpoints
-
React Setup (with
--framework react)- Sets up complete React + TypeScript environment
- Configures esbuild or vite for frontend builds
- Creates welcome page with getting started guide
- Installs necessary npm packages
| Option | Description |
|---|---|
--framework react |
Set up React + TypeScript environment |
- ✅ New projects starting with AshTypescript
- ✅ Adding AshTypescript to existing Phoenix projects
- ✅ Setting up frontend with React integration
- ❌ Projects that already have AshTypescript installed
This is the recommended approach for initial setup.
Recommended approach for most projects. This command runs code generation for all Ash extensions in your project, including AshTypescript.
# Generate types for all Ash extensions including AshTypescript
mix ash.codegen --devFor detailed information about mix ash.codegen, see the Ash documentation.
Generate TypeScript types, RPC clients, Zod schemas, and validation functions only for AshTypescript.
# Basic generation (AshTypescript only)
mix ash_typescript.codegen
# Custom output location
mix ash_typescript.codegen --output "frontend/src/api/ash.ts"
# Custom RPC endpoints
mix ash_typescript.codegen \
--run_endpoint "/api/rpc/run" \
--validate_endpoint "/api/rpc/validate"
# Check if generated code is up to date (CI usage)
mix ash_typescript.codegen --check
# Preview generated code without writing to file
mix ash_typescript.codegen --dry_run| Option | Type | Default | Description |
|---|---|---|---|
--output FILE |
string |
assets/js/ash_rpc.ts |
Output file path for generated TypeScript |
--run_endpoint PATH |
string |
/rpc/run |
RPC run endpoint path |
--validate_endpoint PATH |
string |
/rpc/validate |
RPC validate endpoint path |
--check |
boolean |
false |
Check if generated code is up to date (exit 1 if not) |
--dry_run |
boolean |
false |
Print generated code to stdout without writing file |
When run, this task generates:
-
TypeScript Interfaces
- Resource types with field metadata
- Schema types for field selection
- Result types for each action
-
RPC Client Functions
- HTTP-based RPC functions for each action
- Channel-based RPC functions (if enabled)
- Type-safe configuration objects
-
Filter Input Types
- Comprehensive filter operators
- Type-safe query building
- Nested relationship filtering
-
Zod Validation Schemas (if enabled)
- Runtime type validation
- Schema for each resource
- Nested validation support
-
Form Validation Functions
- Client-side validation helpers
- Error message handling
- Field-level validation
-
Typed Query Constants
- Pre-configured field selections
- SSR-optimized types
- Type-safe result extraction
-
Custom Type Imports
- Imports for custom types
- Integration with external types
- Type mapping support
Basic Generation:
mix ash_typescript.codegenCustom Output Location:
mix ash_typescript.codegen --output "frontend/src/api/ash.ts"Custom RPC Endpoints:
mix ash_typescript.codegen \
--run_endpoint "/api/rpc/run" \
--validate_endpoint "/api/rpc/validate"CI Check:
# In CI pipeline - fails if generated code is out of date
mix ash_typescript.codegen --checkPreview Without Writing:
# See what would be generated
mix ash_typescript.codegen --dry_run | less- ✅ Want to run codegen specifically for AshTypescript
- ✅ Need custom output paths or endpoints
- ✅ Debugging generated TypeScript code
- ✅ CI/CD pipelines with
--checkflag - ❌ Have other Ash extensions that need codegen (use
mix ash.codegen)
For projects using test-only resources (common in library development), use the test environment:
# Generate types in test environment
MIX_ENV=test mix ash_typescript.codegen
# Or use the test.codegen alias (if defined)
mix test.codegenAdd to your mix.exs:
defp aliases do
[
"test.codegen": ["cmd MIX_ENV=test mix ash_typescript.codegen"],
# ... other aliases
]
end# 1. Make changes to resources or domain configuration
vim lib/my_app/resources/todo.ex
# 2. Generate TypeScript types
mix ash.codegen --dev
# 3. Verify TypeScript compilation (in frontend directory)
cd assets && npm run typecheck
# 4. Run tests
mix test# In your CI pipeline (.github/workflows/ci.yml, etc.)
# Check generated code is up to date
mix ash_typescript.codegen --check
# If out of date, CI fails with:
# "Generated TypeScript code is out of date. Run: mix ash_typescript.codegen"Example GitHub Actions:
- name: Check TypeScript codegen
run: mix ash_typescript.codegen --check
- name: Type check generated code
run: |
cd assets
npm run typecheckAdd to .git/hooks/pre-commit:
#!/bin/bash
# Regenerate TypeScript on commit
mix ash_typescript.codegen --check || {
echo "TypeScript code out of date. Regenerating..."
mix ash_typescript.codegen
git add assets/js/ash_rpc.ts
}Problem: Command runs but generates empty output or reports no domains.
Solution: Ensure you're in the correct MIX_ENV:
# Wrong - uses dev environment
mix ash_typescript.codegen
# Correct - uses test environment for test resources
MIX_ENV=test mix ash_typescript.codegenProblem: TypeScript compilation fails after generation.
Solution: Check for:
- Invalid field names (use field name mapping)
- Custom types not defined in imported modules
- Missing type mapping overrides for dependency types
See Configuration Reference for field name mapping and type overrides.
Problem: Made changes to resources but generated TypeScript unchanged.
Solution:
- Recompile Elixir code:
mix compile --force - Regenerate TypeScript:
mix ash_typescript.codegen - Verify output file path matches configuration
Problem: Cannot write to output file.
Solution: Check file permissions and directory structure:
# Ensure directory exists
mkdir -p assets/js
# Check permissions
ls -la assets/js
# Fix if needed
chmod 755 assets/js- Configuration Reference - Configure code generation
- Getting Started Tutorial - Initial setup guide
- Troubleshooting Reference - Common problems and solutions