Using TypeScript in Defold game engine


Hi, I try to use TypeScript as scripting lang in Defold. A made some tests and it works!. Basic idea - Transpile TypeScript to Lua.

As benefits we have TypeScript and VSCode with incredible TS support. TS is very popular in web development now and TS support in Defold make it best web game engine for many people who already known TS.

It’s early version with very basic functionally (currenly have only functions for example projects) but it works. A lot to do. Use an example project for basic tests. Do not hesitate to contribute! :grinning:

An endless runner follows a pattern? (SOLVED)

Not sure how to use it or how it can support Lua in full, but it is interesting.


Do not need support Lua in full. It use basic Lua functions and construction to trinspile TypeScript. Generated Lua code is very clean and human readable.

Here is TS code.

import { Unit } from "./modules/unit";

let unit: Unit

function init(self: any) {
    print("The amazing world of Defold TypeScript")

function update(self: any, dt: number) {

And here is output:

local unit0 = require("modules.unit")
local Unit = unit0.Unit
local unit = nil

function init(self)
    print("The amazing world of Defold TypeScript")
function update(self,dt)


Using TS you get strong type check, typed arguments, classes, inheritance and so on. All reflects to lua basic constructions. TS to Lua work the same way as TS to JS. Very usefulfor big projects support.


Don’t see reasons why this shouldn’t work. I think there was a similar project for Defold but with Haxe - A nice feature would be to provide TS bindings to Defold API (generate it?) so you would get some code assistance while typing.


This is what we are currently working on. It’s not hard but require manual work (some decisions about types for functions arguments)


New working version is here. TypeScript file now have all declarations for Defold API. !

You can download working project on GitHub


Additionally I have create simple script that working in watch mode and prepare lua files automatically just when you save any TypeScript file from project. Process is fully automated now. Just 3 steps to repeat until game do not finished.

  • Write TypeScript code in Visual Studio Code.
  • Save it
  • Go to Editor and build game.


Short video to show how it works.


Very interesting. Does it mean, if you have JS coding expirience, you are very close to JS because of TypeScript, or is it a whole different story? Just in Terms of “feeling home / feeling familiar” with the language. I am very new to LUA, this is why i am asking …


You can use JS as TypeScript is a superset of JavaScript.
You can use JS and start to add type notations (firs steps to TS). :grinning:


Okay…sounds good :yum:


wow! It’s very interesting