
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
typescript-to-lua
Advanced tools
A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!
A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!
Large projects written in lua can become hard to maintain and make it easy to make mistakes. Writing code in TypeScript instead improves maintainability, readability and robustness, with the added bonus of good IDE support. This project is useful in any environment where Lua code is accepted, with the powerful option of simply declaring any existing API using TypeScript declaration files.
More detailed documentation and info on writing declarations can be found on the wiki.
Changelog can be found in CHANGELOG.md
Install
npm install -g typescript-to-lua
Compile Files
tstl path/to/file.ts path/to/other-file.ts
Compile Projects
tstl -p path/to/tsconfig.json
Compile project in watch mode
tstl -p path/to/tsconfig.json --watch
Example tsconfig.json
{
  "compilerOptions": {
    "target": "esnext",
    "lib": ["esnext"],
    "strict": true
  },
  "tstl": {
    "luaTarget": "JIT"
  }
}
All contributions are welcome, but please read our contribution guidelines!
The real power of this transpiler is usage together with good declarations for the Lua API provided. Some examples of Lua interface declarations can be found here:
npm run build to build the project.
npm run test to run tests.
npm run test-threaded runs test in parallel, faster but less detailed output.
npm run coverage or npm run coverage-html to generate a coverage report.
This compiler works great in combination with the Sublime Text Typescript plugin (available through the package manager as TypeScript).
You can simply open your typescript project assuming a valid tsconfig.json file is present. The default TypeScript plugin will provide all functionality of a regular TypeScript project.
To add the option to build with the Lua transpiler instead of the regular typescript compiler, go to Tools > Build System > New Build System.... In the new sublime-build file that opens, enter the following (adjust path to tstl if not installed globally):
{
    "cmd": ["tstl", "-p", "$file"],
    "shell": true
}
Save this in your Sublime settings as a TypeScriptToLua.sublime-build. You can now select the TypeScriptToLua build system in Tools > Build System to build using the normal hotkey (ctrl+B), or if you have multiple TypeScript projects open, you can choose your compiler before building by pressing ctrl+shift+B.
0.23.0
Added support for OmittedExpression in array literals and array binding patterns.
Added support for tagged template literals.
Changed output lua formatting to be more debugger-friendly.
Various improvements to source maps.
Fixed an issue with the interaction of super calls and exported classes.
Fixed @noResolution not working on named modules.
Fixed namespace merging not working due to an earlier change.
Some refactoring and plumbing for the website.
FAQs
A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!
The npm package typescript-to-lua receives a total of 2,853 weekly downloads. As such, typescript-to-lua popularity was classified as popular.
We found that typescript-to-lua demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.