Defold API
Getting accurate types for the Defold API is an important part of ts-defold. Here are some ways to get the definitions you need:
✨ The types
library is built-in into all ts-defold templates, and is automatically
published to keep up with the latest changes to Defold.
🌟 TS-Defold Types II
is a drop-in alternative for the types
library, with hand-written patches to provide for
more accurate and useful types.
💥 Defold Annotations for Typescript
Is a tool for generating types based on the Defold API, with more accurate types and better coverage
of Lua features than the default types
.
Working with Messages
The Defold engine is built around communication using messages, so it helps to have accurate definitions of the built-in messages.
🎶 Utility Types include messages.
💥 Defold Annotations for Typescript can generate a definitions file with Defold's built-in messages.
Working with Vector Math
TypeScript doesn't have a built-in way to understand the resulting type of an operation involving vectors.
const result = go.get_position() + vmath.vector3(1, 1, 1); // type: number ?!??
If you're confident about the result, you can cast the type:
const result = (go.get_position() + vmath.vector3(1, 1, 1)) as vmath.vector3; // type: vmath.vector3
Or you can use the Operator Map Types provided by TSTLTSTL - TypeScriptToLua Transpiler An extension to the TypeScript compiler that transpiles TypeScript code to Lua to enable full type checking.
🎶 Utility Types include all relevant vector math operations.
namespace vmath {export const add: LuaAddition<vmath.vector3, vmath.vector3, vmath.vector3>;}const result = vmath.add(go.get_position(), vmath.vector3(1, 1, 1)) // type: vmath.vector3