ts2asl
raw JSON → 0.1.0 verified Fri May 01 auth: no javascript
ts2asl is a TypeScript-to-AWS State Language (ASL) transpiler that converts TypeScript code into Amazon States Language JSON, enabling developers to author AWS Step Functions using standard TypeScript syntax. Version 0.1.0 is the initial release with a focus on a subset of TypeScript features, including variables, conditionals, loops, and async/await. It targets Node >=12.0.0 and ships TypeScript types. Key differentiators vs direct ASL authoring: static type checking, IDE support, and the ability to use familiar programming constructs. Current limitations include no support for classes, enums, or complex generics. Release cadence is not yet established as it is a young project.
Common errors
error Error: Cannot find module 'ts2asl' ↓
cause Package not installed or ESM configuration missing.
fix
Run 'npm install ts2asl' and ensure 'type':'module' in package.json.
error TypeError: compile is not a function ↓
cause Using CommonJS require instead of ESM import.
fix
Use 'import { compile } from 'ts2asl'' instead of 'require'.
error SyntaxError: Unexpected token 'export' ↓
cause Running ESM code in a non-ESM context (e.g., Node.js <12 or CJS environment).
fix
Set 'type':'module' in package.json or use .mjs extension.
error Error: Unsupported construct: ClassDeclaration ↓
cause ts2asl does not support classes in the current version.
fix
Replace class with functions and objects.
Warnings
breaking ts2asl v0.1.0 does not support TypeScript classes, enums, or namespaces. Using these will cause compile errors or undefined behavior. ↓
fix Refactor code to use only functions, variables, conditionals, loops, and async/await.
gotcha Only a subset of JavaScript/TypeScript built-ins are supported. For example, Array.map, Promise.all, etc. may be silently ignored or cause errors. ↓
fix Check the supported features list: https://github.com/Stedi/ts2asl#supported-features
gotcha The package is ESM-only and requires Node.js >=12.0.0 with 'type': 'module' in package.json or .mjs extension. ↓
fix Ensure 'type': 'module' is set in your package.json.
deprecated No deprecation notices yet for v0.1.0 as it's the first release. ↓
fix Stay tuned for future versions.
Install
npm install ts2asl yarn add ts2asl pnpm add ts2asl Imports
- default wrong
const ts2asl = require('ts2asl')correctimport ts2asl from 'ts2asl' - compile wrong
const { compile } = require('ts2asl')correctimport { compile } from 'ts2asl' - CompileOptions wrong
import { CompileOptions } from 'ts2asl'correctimport type { CompileOptions } from 'ts2asl'
Quickstart
import { compile } from 'ts2asl';
const code = `
async function myFunction(input: { name: string }): Promise<string> {
const greeting = "Hello, " + input.name;
return greeting;
}
`;
const result = compile(code, {
fileName: 'myFunction.ts',
target: 'stepfunctions'
});
console.log(JSON.stringify(result.asl, null, 2));