Skip to content

Commit

Permalink
feat: finish API page
Browse files Browse the repository at this point in the history
  • Loading branch information
thinknathan committed Aug 5, 2024
1 parent 424b54d commit d21ce63
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions content/configuration/def-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,38 @@ 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

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:
Expand All @@ -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 {
Expand Down

0 comments on commit d21ce63

Please sign in to comment.