Close
Close full mode
logots-defold

TypeScript Config

githubEdit on Github
Last update: 20 days ago by Justin WalshReading time: 2 min

The TypeScript and TypeScriptToLua configuration is set in .tsconfig.json within the root of your project.

TypeScript Options

The compiler options are configured with sane defaults that are recommended for best results when working with TSTLTSTL - TypeScriptToLua Transpiler An extension to the TypeScript compiler that transpiles TypeScript code to lua but you may want to adjust a few options, or configure to your liking.

Some notable options include:

  • "types": [] - Any additional TSTLTSTL - TypeScriptToLua Transpiler An extension to the TypeScript compiler that transpiles TypeScript code to lua types you would like to use must be included here.
  • "exclude": [] - TypeScript by default will look for types relative to the .tsconfig.json file and you may need to exclude some folders from being considered as you make the project structure your own.

TypeScriptToLua Options

These options are contained under the "tstl" key in the .tsconfig.json and are used to configure the behavior of the TypeScriptToLua transpiler.

TSTLTSTL - TypeScriptToLua Transpiler An extension to the TypeScript compiler that transpiles TypeScript code to lua comes pre-configured out of the box with some additional plugins that aid in translating TypeScript code to lua as used by Defold.

These options are of particular concern:

  • "luaTarget": "5.1" - Defold recommends targeting lua 5.1 for the broadest support of deployment targets.
    If you do not want to release your game on an HTML5 target, you may want to modify this to bring in additional syntax features.

  • "luaLibImport": "require" - This setting is used to generate the lualib_bundle.lua and then insert a require statement at the top of each script to bring in the support library.
    You may also define this as inline, though it causes you bundle size to increase due to code duplication, and is generally not recommended.

  • "trimExtensions": true - This setting is used to enable proper file naming through a patch to the TSTLTSTL - TypeScriptToLua Transpiler An extension to the TypeScript compiler that transpiles TypeScript code to lua transpiler code. You should typically leave this enabled, otherwise .lua will be appended to each of your game scripts.
    You should follow the pattern of my-script.script.ts, my-gui.gui_script.ts etc. so that Defold will properly categorize and run the generated script in the Defold editor.

🔧 Configuration — Previous
Introduction
Next — 🔧 Configuration
Plugins