{"id":26553,"library":"typescript-to-lua-fixed","title":"TypeScriptToLua","description":"A generic TypeScript to Lua transpiler that lets you write TypeScript code and compile it to Lua. This package (v1.0.1) is a fork requiring TypeScript ~4.4.3. It provides a command-line tool (`tstl`) similar to `tsc`. Key differentiators: preserves TypeScript type safety in Lua projects; supports declaration files for existing Lua APIs; integrates with standard TS tooling (ESLint, Prettier). Release cadence is sporadic; check upstream TypeScriptToLua for active development.","status":"active","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/justchen1369/TypeScriptToLua","tags":["javascript","typescript","lua","tstl","transpiler"],"install":[{"cmd":"npm install typescript-to-lua-fixed","lang":"bash","label":"npm"},{"cmd":"yarn add typescript-to-lua-fixed","lang":"bash","label":"yarn"},{"cmd":"pnpm add typescript-to-lua-fixed","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency: requires TypeScript ~4.4.3 to perform transpilation.","package":"typescript","optional":false}],"imports":[{"note":"ESM named export; default import not supported.","wrong":"import transpile from 'typescript-to-lua'","symbol":"transpile","correct":"import { transpile } from 'typescript-to-lua'"},{"note":"ESM-only package; use import, not require.","wrong":"const transpileString = require('typescript-to-lua').transpileString","symbol":"transpileString","correct":"import { transpileString } from 'typescript-to-lua'"},{"note":"Same as transpile; alternative name for the same function.","wrong":"","symbol":"compile","correct":"import { compile } from 'typescript-to-lua'"},{"note":"Type export for TypeScript users.","wrong":"","symbol":"LuaTranspiler","correct":"import { LuaTranspiler } from 'typescript-to-lua'"}],"quickstart":{"code":"import { transpileString } from 'typescript-to-lua';\nimport { transpile } from 'typescript-to-lua';\nimport * as ts from 'typescript';\n\n// Example: transpile a simple TypeScript class\nconst source = `\nclass Greeter {\n    greeting: string;\n    constructor(message: string) {\n        this.greeting = message;\n    }\n    greet() {\n        return \"Hello, \" + this.greeting;\n    }\n}\n`;\n\nconst result = transpileString(source, {\n    luaTarget: \"5.3\",\n    noHeader: true\n});\n\nconsole.log(result.file?.lua);\n// Output: \n// Greeter = {}\n// function Greeter.new(self, message)\n//   self.greeting = message\n//   return self\n// end\n// function Greeter.greet(self)\n//   return \"Hello, \" .. self.greeting\n// end\n\n// For file-based transpilation:\nconst program = ts.createProgram(['./input.ts'], {});\nconst emitResult = transpile(program, { luaTarget: '5.3' });\nconsole.log(emitResult.emitSkipped ? 'Emit skipped' : 'Emit succeeded');","lang":"typescript","description":"Demonstrates transpiling a TypeScript class to Lua using 'transpileString' and file-based transpilation with 'transpile'."},"warnings":[{"fix":"Consider using 'typescript-to-lua' (original) instead unless you specifically need this fork's fixes.","message":"This is a fixed fork of the original TypeScriptToLua. Use the original for latest features and updates.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Install TypeScript 4.4.3: npm install -D typescript@~4.4.3","message":"Requires TypeScript ~4.4.3 as a peer dependency. Incompatible with newer TypeScript versions (4.5+).","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use result.file?.lua to obtain the output.","message":"The 'transpileString' function returns an object with a 'file' property; access 'file.lua' to get the Lua code.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"npm install -D typescript-to-lua","cause":"Package not installed or missing from node_modules.","error":"Error: Cannot find module 'typescript-to-lua'"},{"fix":"Use named import: import { transpileString } from 'typescript-to-lua'","cause":"Default import used incorrectly (import transpileString from '...') or CommonJS require used.","error":"TypeError: transpileString is not a function"},{"fix":"Ensure 'typescript-to-lua' is installed and types are bundled (they are). May need to add 'typescript-to-lua' to 'types' in tsconfig.json.","cause":"TypeScript cannot locate types for the package.","error":"error TS2688: Cannot find type definition file for 'typescript-to-lua'."},{"fix":"Use transpileString for string input, or create a ts.Program using ts.createProgram for file-based input.","cause":"Confusing transpile with transpileString.","error":"The 'transpile' function requires a TypeScript Program object, not source code."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}