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:


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

1 Like

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.

1 Like

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:

1 Like

Okay…sounds good :yum:

1 Like

wow! It’s very interesting

I’m interested in checking out TypeScript in Defold to take advantage of some of its features in a game I’m working on - Are we able to mix Lua and Typescript? (And do you consider it a good move?) For example, if I would like to move some logic from Lua to Typescript and use OOP when designing some more complex objects for which many times I’m struggling with some problems I’m pretty sure I would neutralize (or at least detect more conveniently and faster) with type checking, compile time detections and so on.

1 Like

Yes, you can mix Lua and TS.
Check this site for more information/docs