TypeScript to VBA Transpiler
raw JSON → 1.0.1 verified Fri May 01 auth: no javascript
TSTVBA is a Node.js CLI tool (v1.0.1) that transpiles TypeScript into VBA modules (.bas and .cls) for Excel/Office automation. It requires Node >=18.0.0 and TypeScript >=5.0.0 as peer dependencies. Key features include class-to-class module mirroring, try/catch-to-On Error mapping, for...of iteration bridging, configurable namespace prefixing, and bundle output with manifest. Unlike generic code generators, it produces real VBA classes, source maps, and integrates directly with tsconfig.json via tstvbaOptions. Maintenance is active on GitHub.
Common errors
error TypeError: Cannot read properties of undefined (reading 'kind') ↓
cause TypeScript version <5.0.0; AST node shape differs.
fix
Upgrade TypeScript to >=5.0.0
error Error: Could not find a valid tsconfig file in path ↓
cause Missing tsconfig.json or tsconfig.tstvba.json; --init not run.
fix
Run 'npx tstvba --init' to generate tsconfig.tstvba.json
error CLI error: 'tstvba' is not recognized as an internal or external command ↓
cause Global install missing or not in PATH.
fix
Use 'npx tstvba' instead of global binary
Warnings
gotcha Node >=18.0.0 required; older versions (e.g., Node 16) will fail with syntax errors. ↓
fix Update Node to version >=18.0.0
gotcha TypeScript peer dependency must be >=5.0.0. Using an older version may break AST traversal. ↓
fix Install TypeScript >=5.0.0 as a devDependency
gotcha Global install vs npx: Global install may conflict with project-level TypeScript versions. Use npx to avoid global dependency issues. ↓
fix Use npx tstvba instead of global install
gotcha Generated .cls files contain metadata headers (VERSION/BEGIN/END + Attribute ...). Copying lines above 'Option Explicit' manually will break class import. ↓
fix Use VBE -> File -> Import File... to import .cls files
Install
npm install typescript-to-vba yarn add typescript-to-vba pnpm add typescript-to-vba Imports
- tstvba CLI wrong
npm install -g typescript-to-vba && tstvba --initcorrectnpx tstvba --init - config import wrong
import { transpileProject } from 'typescript-to-vba';correctconst { transpileProject } = require('typescript-to-vba');
Quickstart
npx tstvba --init
# Generates tsconfig.tstvba.json and lib/vbalib.bas stub
# Then run:
npx tstvba check -p .
npx tstvba -p .
# Output: dist/vba/MyProject.bas + dist/vba/tstvba-manifest.json