Registry / devops / typescript-to-lua

typescript-to-lua

JSON →
library1.34.0jsnpmunverified

TypeScriptToLua (tstl) is a transpiler that converts TypeScript code into Lua. It enables developers to leverage TypeScript's static typing, tooling (like ESLint, Prettier, and VS Code support), and maintainability benefits for projects targeting Lua environments. The current stable version is 1.34.0, and new versions are released regularly, often mirroring TypeScript's own release cadence of roughly every 3 months for major updates, with patch releases as needed. A key differentiator is its ability to generate Lua code compatible with various Lua versions, including a 'universal' target, and its extensive use of TypeScript's type information to produce optimized and portable Lua. It's particularly useful for game development (e.g., Dota 2, Defold, LÖVE 2D, World of Warcraft addons) or any application where Lua scripting is used, allowing for strong type safety and improved development workflows through declaration files for existing Lua APIs.

npm install typescript-to-lua
INSTALL
IMPORT
SIG · TYPESCRIPT-TO-LUA
T
typescript-to-lua
devopsjavascriptv1.34.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

transpileProject
import { transpileProject } from 'typescript-to-lua';
const { transpileProject } = require('typescript-to-lua');
Primary function for transpiling a TypeScript project defined by a tsconfig.json file. Supports ESM imports.
transpileString
import { transpileString } from 'typescript-to-lua';
import * as tstl from 'typescript-to-lua'; const result = tstl.transpileString(...);
Used for transpiling a single TypeScript string into Lua. Named import is preferred over default or namespace imports for specific utilities.
LuaTarget
import { LuaTarget } from 'typescript-to-lua';
Enum used to specify the target Lua version (e.g., LuaTarget.Lua53, LuaTarget.JIT) within compiler options. Necessary for controlling generated Lua features.
CompilerOptions
import type { CompilerOptions } from 'typescript-to-lua';
import { CompilerOptions } from 'typescript-to-lua';
Interface for defining `tstl` specific compiler options, typically used within the `tstl` block of `tsconfig.json` or for programmatic compilation. Use `import type` for type-only imports for better bundling.

Demonstrates setting up `tsconfig.json` for TypeScriptToLua, a simple `main.ts` file, and compiling it to Lua using the `tstl` command. This creates `dist/main.lua`.

{ "compilerOptions": { "target": "esnext", "lib": ["esnext"], "strict": true, "moduleResolution": "node", "rootDir": ".", "outDir": "./dist" }, "tstl": { "luaTarget": "universal", "luaLibImport": "require" }, "include": ["src/**/*.ts"] } // src/main.ts function greet(name: string): string { return `Hello, ${name}!`; } console.log(greet("TypeScriptToLua")); // package.json (excerpt) /* { "name": "my-lua-project", "version": "1.0.0", "devDependencies": { "typescript": "^5.0.0", "typescript-to-lua": "^1.34.0" }, "scripts": { "build": "npx tstl" } } */
tstl --version
Debug
Known issues
breakingBreaking changes frequently occur with TypeScript version upgrades. For example, `typescript-to-lua` v1.10.0 required TypeScript 4.8 and changed how language extensions are distributed, moving from `"typescript-to-lua/..."` to `"types": ["@typescript-to-lua/language-extensions"]` in `tsconfig.json`. Always review the `CHANGELOG.md` when upgrading `typescript-to-lua` or `typescript` versions.
fix
Consult the `CHANGELOG.md` for specific migration steps. Update your `tsconfig.json` to reflect new language extension paths or other configuration changes.
affects: >=1.10.0
breakingThe default `luaTarget` was changed to `"universal"` in version 0.34.0. If you were implicitly relying on `LuaJIT` as the default target, you must now explicitly set `"luaTarget": "JIT"` in your `tsconfig.json` file.
fix
Explicitly set `"tstl": { "luaTarget": "JIT" }` in your `tsconfig.json` if your project requires LuaJIT specific output.
affects: >=0.34.0
gotchaTypeScriptToLua converts `null` and `undefined` to Lua's `nil`. While often interchangeable in TypeScript, they are distinct concepts in JavaScript. It is recommended to prefer `undefined` over `null` in `tstl` codebases to better represent the transpiled Lua and align with TypeScript idioms.
fix
Consistently use `undefined` instead of `null` in your TypeScript code for Lua transpilation. Use ESLint rules like `strict-boolean-expressions` to enforce explicit boolean logic.
affects: >=0.1.0
gotchaLua has a limit of 200 local variables within a single function. Large TypeScriptToLua programs with many imports or extensively large functions can hit this limit at runtime, leading to crashes that the transpiler does not catch at compile time. Each import statement typically creates two local variables in Lua.
fix
Refactor large functions into smaller ones. Consolidate imports where possible, or restructure code to reduce the number of local variables in a single scope. Consider using different module bundling strategies if available.
affects: >=0.1.0
gotchaBehavioral differences exist for some JavaScript features in Lua. For example, JavaScript's loose equality (`==`) and strict equality (`===`) are both translated to strict equality in Lua. Array `length` behavior and `Array.sort` stability also differ from JavaScript.
fix
Be explicit with comparisons using `===` in TypeScript. Be aware of Lua's array conventions when manipulating array `length` and if stable sorting is required, implement a custom sorting algorithm or use a Lua-specific library. Use ESLint rules like `eqeqeq` and `strict-boolean-expressions`.
affects: >=0.1.0
gotchaSome standard TypeScript compiler options, such as `outFile`, `importHelpers`, `target` (should always be `esnext`), and `module` (should be omitted or default to `ES2015`), are either ignored or require specific values for `typescript-to-lua` to function correctly. Additionally, `composite`, `build.incremental`, and `emitDecoratorMetadata` are not supported.
fix
Refer to the `typescript-to-lua` documentation for compatible `tsconfig.json` options. Use `luaBundle` instead of `outFile` and `luaLibImport` instead of `importHelpers`.
affects: >=0.1.0
Errors
Common errors & fixes
Error: TS5023: Unknown compiler option 'luaTarget'.
The `tstl` specific options are not correctly nested within the `tstl` block in `tsconfig.json` or the `tsconfig.json` schema is not being recognized.
fix
Ensure `luaTarget` and other `tstl` options are inside a `"tstl": {}` object in your `tsconfig.json`. Example: `{
  "compilerOptions": { ... },
  "tstl": {
    "luaTarget": "universal"
  }
}`. Ensure your IDE is using the correct schema by adding `"$schema": "https://raw.githubusercontent.com/TypeScriptToLua/TypeScriptToLua/master/tsconfig-schema.json"`
Error: Cannot find module 'typescript-to-lua' or its corresponding type declarations.
The `typescript-to-lua` package is not installed, or `typescript` (its peer dependency) is missing, or `node_modules` are not properly resolved.
fix
Run `npm install -D typescript typescript-to-lua` to ensure both the transpiler and its peer TypeScript dependency are installed. If issues persist, try `rm -rf node_modules && npm install`.
Runtime Error: attempt to call a nil value (global 'console')
The transpiled Lua code is attempting to access a global object like `console` which exists in browser/Node.js environments but not inherently in a Lua runtime. `typescript-to-lua` does not automatically polyfill all browser/Node.js globals.
fix
Provide Lua-specific implementations or declarations for global objects and functions you use (e.g., `console.log` could map to Lua's `print`). Use TypeScript declaration files (`.d.ts`) to inform the transpiler about these Lua-native APIs. For instance, declare `declare function print(...args: any[]): void;` and map `console.log` to `print`.
Upgrade
Version history
1.34.0latest on npm
Audit
Dependencies
typescriptrequiredRequired peer dependency for the TypeScript compiler API.
Agent activity
2 hits · last 30 days
node
2
Resources