@defold-typescript/types 0.8.3 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/api-targets.json +18 -0
- package/generated/b2d_body.d.ts +348 -0
- package/generated/buffer.d.ts +3 -0
- package/generated/camera.d.ts +236 -1
- package/generated/collectionfactory.d.ts +4 -0
- package/generated/factory.d.ts +4 -0
- package/generated/font.d.ts +81 -0
- package/generated/go.d.ts +53 -0
- package/generated/gui.d.ts +264 -49
- package/generated/html5.d.ts +17 -13
- package/generated/http.d.ts +16 -0
- package/generated/image.d.ts +24 -0
- package/generated/json.d.ts +2 -0
- package/generated/kinds/gui-script.d.ts +3 -0
- package/generated/kinds/render-script.d.ts +3 -0
- package/generated/kinds/script.d.ts +3 -0
- package/generated/model.d.ts +14 -0
- package/generated/msg.d.ts +17 -11
- package/generated/particlefx.d.ts +6 -0
- package/generated/physics.d.ts +32 -0
- package/generated/profiler.d.ts +14 -0
- package/generated/render.d.ts +109 -0
- package/generated/resource.d.ts +223 -0
- package/generated/socket.d.ts +4 -0
- package/generated/sound.d.ts +6 -0
- package/generated/sprite.d.ts +5 -0
- package/generated/sys.d.ts +136 -0
- package/generated/tilemap.d.ts +2 -0
- package/generated/timer.d.ts +3 -0
- package/generated/vmath.d.ts +109 -93
- package/generated/window.d.ts +24 -1
- package/index.d.ts +8 -0
- package/package.json +1 -1
- package/scripts/fidelity-baseline.json +18 -2
- package/scripts/regen.ts +5 -0
- package/scripts/signature-store-io.ts +18 -0
- package/scripts/sync-api-docs.ts +208 -12
- package/src/core-types.ts +4 -2
- package/src/doc-comment.ts +42 -5
- package/src/emit-dts.ts +20 -1
- package/src/engine-globals.d.ts +2 -0
- package/src/example-store.ts +11 -7
- package/src/index.ts +18 -1
- package/src/msg-overloads.d.ts +3 -0
- package/src/signature-store.ts +20 -0
- package/src/window-event-guard.d.ts +52 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// A hand-authored override for one ref-doc element's signature, sourced from
|
|
2
|
+
// the `lua-types` declarations the compiler actually enforces. The ref-doc's
|
|
3
|
+
// own signatures are far weaker (`...` params show `unknown`, no return types),
|
|
4
|
+
// so these strengthen the rendered signature while the ref-doc prose stays.
|
|
5
|
+
export interface SignatureOverride {
|
|
6
|
+
signatures: string[];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// An FQN (`io.open`, `file:read`, …) maps to one override. An element with
|
|
10
|
+
// several overloads carries more than one entry in `signatures`, in authored
|
|
11
|
+
// order (the order the docs should render them).
|
|
12
|
+
export type SignatureStore = Record<string, SignatureOverride>;
|
|
13
|
+
|
|
14
|
+
// Return the override for an FQN, or `null` when the store has no entry. Pure
|
|
15
|
+
// and dependency-free like `example-store.ts`: this module is reachable from
|
|
16
|
+
// `index.ts`, so a `node:fs`/ambient-`Bun` reference here would fail type-checking
|
|
17
|
+
// in every downstream consumer that compiles the shipped `src/` graph.
|
|
18
|
+
export function lookupSignature(store: SignatureStore, fqn: string): SignatureOverride | null {
|
|
19
|
+
return store[fqn] ?? null;
|
|
20
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** @noSelfInFile */
|
|
2
|
+
|
|
3
|
+
// `window.set_listener` hands the callback `event` and `data` as two *separate*
|
|
4
|
+
// params, and the `WINDOW_EVENT_*` constants are branded numbers — so TS can
|
|
5
|
+
// neither correlate the two params nor use a branded number as a discriminant.
|
|
6
|
+
// This guard re-introduces the discriminant at the use site, narrowing the
|
|
7
|
+
// untyped `data` payload (only `WINDOW_EVENT_RESIZED` carries fields). It mirrors
|
|
8
|
+
// `isMessage` for `on_message`; the transpiler lowers the call to a bare
|
|
9
|
+
// `event == window.WINDOW_EVENT_*` (window-event-guard-lowering.ts), so this
|
|
10
|
+
// package emits no runtime Lua.
|
|
11
|
+
type WindowEventKind =
|
|
12
|
+
| typeof window.WINDOW_EVENT_FOCUS_LOST
|
|
13
|
+
| typeof window.WINDOW_EVENT_FOCUS_GAINED
|
|
14
|
+
| typeof window.WINDOW_EVENT_RESIZED
|
|
15
|
+
| typeof window.WINDOW_EVENT_ICONFIED
|
|
16
|
+
| typeof window.WINDOW_EVENT_DEICONIFIED;
|
|
17
|
+
|
|
18
|
+
type WindowEventData<K extends WindowEventKind> = K extends typeof window.WINDOW_EVENT_RESIZED
|
|
19
|
+
? { width: number; height: number }
|
|
20
|
+
: undefined;
|
|
21
|
+
|
|
22
|
+
declare global {
|
|
23
|
+
/**
|
|
24
|
+
* Type guard for a `window.set_listener` callback: narrows the untyped `data`
|
|
25
|
+
* payload to its event-specific shape when `event` matches a known
|
|
26
|
+
* `WINDOW_EVENT_*` constant. The engine hands `event` and `data` as separate
|
|
27
|
+
* params and the constants are branded numbers, so TS cannot auto-narrow `data`
|
|
28
|
+
* from an `event === window.WINDOW_EVENT_RESIZED` check — this guard
|
|
29
|
+
* re-introduces the discriminant. Only `WINDOW_EVENT_RESIZED` carries fields
|
|
30
|
+
* (`{ width, height }`); every other event narrows `data` to `undefined`.
|
|
31
|
+
*
|
|
32
|
+
* @param event - the event constant the callback received.
|
|
33
|
+
* @param data - the untyped data payload the callback received.
|
|
34
|
+
* @param expected - the window event constant to test against (e.g. `window.WINDOW_EVENT_RESIZED`).
|
|
35
|
+
* @returns `true` when `event` matches `expected`, narrowing `data` to that event's payload.
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* window.set_listener((self, event, data) => {
|
|
39
|
+
* if (isWindowEvent(event, data, window.WINDOW_EVENT_RESIZED)) {
|
|
40
|
+
* print("resized:", data.width, data.height);
|
|
41
|
+
* }
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
function isWindowEvent<K extends WindowEventKind>(
|
|
46
|
+
event: unknown,
|
|
47
|
+
data: unknown,
|
|
48
|
+
expected: K,
|
|
49
|
+
): data is WindowEventData<K>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export {};
|