diff --git a/content/configuration/def-api.md b/content/configuration/def-api.md index 5f3a1a9..0f9f655 100644 --- a/content/configuration/def-api.md +++ b/content/configuration/def-api.md @@ -3,11 +3,30 @@ title: "Defold API" order: 3 --- -Getting accurate types for the Defold API is an important part of ts-defold. Here are some ways to get the definitions you need: +Getting accurate types for the Defold API is an important part of ts-defold. Here are some +ways to get the definitions you need: -:sparkles: The `types` library is built-in into all ts-defold templates, and is automatically published to keep up with the latest changes to Defold. -:star2: [TS-Defold Types II](https://github.com/thinknathan/ts-defold-types) is a drop-in alternative for the `types` library, with hand-written patches to provide for more accurate and useful types. -:boom: [Defold Annotations for Typescript](https://github.com/elMuso/defold-annotations-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`. +:sparkles: The `types` library is built-in into all ts-defold templates, and is automatically +published to keep up with the latest changes to Defold. + +:star2: [TS-Defold Types II](https://github.com/thinknathan/ts-defold-types) +is a drop-in alternative for the `types` library, with hand-written patches to provide for +more accurate and useful types. + +:boom: [Defold Annotations for Typescript](https://github.com/elMuso/defold-annotations-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](https://defold.com/manuals/message-passing/), +so it helps to have accurate definitions of the built-in messages. + +:notes: [Utility Types](https://github.com/thinknathan/tsd-util-types/tree/main/types) +include messages. + +:boom: [Defold Annotations for Typescript](https://github.com/elMuso/defold-annotations-typescript/) +can generate a definitions file with Defold's built-in messages. # Working with Vector Math @@ -15,7 +34,7 @@ TypeScript doesn't have a built-in way to understand the resulting type of an operation involving vectors. ```ts -const result = go.get_position() + vmath.vector3(1, 1, 1); // type: number :exclamation: +const result = go.get_position() + vmath.vector3(1, 1, 1); // type: number ?!?? ``` If you're confident about the result, you can cast the type: @@ -24,11 +43,12 @@ 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](https://typescripttolua.github.io/docs/advanced/language-extensions#operator-map-types) +Or you can use the +[Operator Map Types](https://typescripttolua.github.io/docs/advanced/language-extensions#operator-map-types) provided by TSTL to enable full type checking. -:sparkles: Here's a [library of types](https://github.com/thinknathan/tsd-util-types/blob/main/types/vmath.d.ts) -with all relevant vector math operations. +:notes: [Utility Types](https://github.com/thinknathan/tsd-util-types/blob/main/types/vmath.d.ts) +include all relevant vector math operations. ```ts namespace vmath {