Registry /
devops / typescript-to-lua-fixed
Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
transpile
✓ import { transpile } from 'typescript-to-lua'
✗ import transpile from 'typescript-to-lua'
ESM named export; default import not supported.
transpileString
✓ import { transpileString } from 'typescript-to-lua'
✗ const transpileString = require('typescript-to-lua').transpileString
ESM-only package; use import, not require.
compile
✓ import { compile } from 'typescript-to-lua'
Same as transpile; alternative name for the same function.
LuaTranspiler
✓ import { LuaTranspiler } from 'typescript-to-lua'
Type export for TypeScript users.
Demonstrates transpiling a TypeScript class to Lua using 'transpileString' and file-based transpilation with 'transpile'.
import { transpileString } from 'typescript-to-lua';
import { transpile } from 'typescript-to-lua';
import * as ts from 'typescript';
// Example: transpile a simple TypeScript class
const source = `
class Greeter {
greeting: string;
constructor(message: string) {
this.greeting = message;
}
greet() {
return "Hello, " + this.greeting;
}
}
`;
const result = transpileString(source, {
luaTarget: "5.3",
noHeader: true
});
console.log(result.file?.lua);
// Output:
// Greeter = {}
// function Greeter.new(self, message)
// self.greeting = message
// return self
// end
// function Greeter.greet(self)
// return "Hello, " .. self.greeting
// end
// For file-based transpilation:
const program = ts.createProgram(['./input.ts'], {});
const emitResult = transpile(program, { luaTarget: '5.3' });
console.log(emitResult.emitSkipped ? 'Emit skipped' : 'Emit succeeded');
tstl --version
Errors
Common errors & fixes
Error: Cannot find module 'typescript-to-lua'
Package not installed or missing from node_modules.
fixnpm install -D typescript-to-lua
TypeError: transpileString is not a function
Default import used incorrectly (import transpileString from '...') or CommonJS require used.
fixUse named import: import { transpileString } from 'typescript-to-lua' error TS2688: Cannot find type definition file for 'typescript-to-lua'.
TypeScript cannot locate types for the package.
fixEnsure 'typescript-to-lua' is installed and types are bundled (they are). May need to add 'typescript-to-lua' to 'types' in tsconfig.json.
The 'transpile' function requires a TypeScript Program object, not source code.
Confusing transpile with transpileString.
fixUse transpileString for string input, or create a ts.Program using ts.createProgram for file-based input.
Audit
Dependencies
typescriptrequiredPeer dependency: requires TypeScript ~4.4.3 to perform transpilation.