@spidunno/desmos-types 1.13.4 → 1.13.6
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 +41 -6
- package/internals/generated/objects.d.ts +901 -901
- package/internals/generated/views.d.ts +7 -7
- package/module/index.d.ts +1950 -0
- package/module/internals.d.ts +8184 -0
- package/package.json +12 -3
package/README.md
CHANGED
|
@@ -6,11 +6,11 @@ the graphing calculator, geometry tool, 3D calculator, and the four-function and
|
|
|
6
6
|
## Install
|
|
7
7
|
|
|
8
8
|
```sh
|
|
9
|
-
npm install --save-dev @spidunno/desmos-types@~1.13.
|
|
9
|
+
npm install --save-dev @spidunno/desmos-types@~1.13.6
|
|
10
10
|
```
|
|
11
11
|
|
|
12
12
|
The package's major and minor version match the Desmos API version it describes; patch releases
|
|
13
|
-
are fixes to the types. Use a tilde range (`~1.13.
|
|
13
|
+
are fixes to the types. Use a tilde range (`~1.13.6`), not npm's default caret (`^`), so you only
|
|
14
14
|
get type fixes for the API version you load.
|
|
15
15
|
|
|
16
16
|
## Usage
|
|
@@ -53,6 +53,30 @@ the API only exists as the global that `calculator.js` creates.
|
|
|
53
53
|
import type { GraphingCalculator, GraphState } from '@spidunno/desmos-types';
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
+
### Without a global
|
|
57
|
+
|
|
58
|
+
Importing from `@spidunno/desmos-types` (or `/internals`) still declares the global `Desmos`, so
|
|
59
|
+
code that uses the global type-checks even when the program never loaded `calculator.js` as a
|
|
60
|
+
script. If you load the API some other way, for example into a scope of your own so that
|
|
61
|
+
`window.Desmos` never exists, use the module-only entry points instead. They declare the same
|
|
62
|
+
types, but nothing global:
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import type { Desmos } from '@spidunno/desmos-types/module'; // or '/module/internals'
|
|
66
|
+
|
|
67
|
+
async function loadDesmos(): Promise<typeof Desmos> {
|
|
68
|
+
/* ... */
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const api = await loadDesmos();
|
|
72
|
+
const calculator: Desmos.GraphingCalculator = api.GraphingCalculator(element);
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
`Desmos` is a type-only export, since the package contains no JavaScript: using it as a value is a
|
|
76
|
+
compile error, and editors auto-import it with `import type` (or with a plain import that
|
|
77
|
+
TypeScript removes, unless `verbatimModuleSyntax` is on). Don't also include the default entry
|
|
78
|
+
points (in `compilerOptions.types` or a `/// <reference>`), or the global comes back.
|
|
79
|
+
|
|
56
80
|
## Layout
|
|
57
81
|
|
|
58
82
|
| File | Contents |
|
|
@@ -75,6 +99,7 @@ import type { GraphingCalculator, GraphState } from '@spidunno/desmos-types';
|
|
|
75
99
|
| `types/mathquill.d.ts` | The bundled MathQuill fork |
|
|
76
100
|
| `types/desmos.d.ts` | `enabledFeatures`, `supportedLanguages`, `imageFileToDataURL`, `version`, `Window.Desmos` |
|
|
77
101
|
| `internals/` | Opt-in internals (see [Internals](#internals)); `internals/generated/` is generated |
|
|
102
|
+
| `module/` | Module-only copies of `index.d.ts` and `internals/index.d.ts` (see [Without a global](#without-a-global)), built by `npm run build:module` |
|
|
78
103
|
| `scripts/extract-internals.cjs` | Regenerates `internals/generated/` from a bundle |
|
|
79
104
|
|
|
80
105
|
## Sources and conventions
|
|
@@ -140,10 +165,20 @@ Everything here is internal to Desmos and changes between builds, even within v1
|
|
|
140
165
|
| Hand-written | `internals/*.d.ts` | Precise types for the parts mods use, checked against the bundle source |
|
|
141
166
|
|
|
142
167
|
In the generated layer, property types come from observed values. A method's return type comes from
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
168
|
+
calling side-effect-free getters such as `get*` and `is*`, or from what its source returns: literals,
|
|
169
|
+
operators, object literals, `this.x` (typed as `this["x"]`, so refinements of `x` carry over), and
|
|
170
|
+
calls to other methods and bundle functions, whose return types are inferred the same way. A return
|
|
171
|
+
type stays `unknown` if any returned value can't be typed. Anything that couldn't be determined is
|
|
172
|
+
`unknown`. Action payload field names are reliable, but their value types are often inferred from the
|
|
173
|
+
field name.
|
|
174
|
+
|
|
175
|
+
The bundle is minified, so parameter names are recovered from how each method uses them:
|
|
176
|
+
`this.x = p` and `{ x: p }` name it `x`, `dispatch({ type, x: p })` also copies the action field's
|
|
177
|
+
type, and passing `p` to another method or bundle function (`this.getItemModel(p)`) reuses that
|
|
178
|
+
function's inferred name and type. Defaults, arithmetic, exhaustive `switch`es and `.type`
|
|
179
|
+
comparisons give types (`id: string`, `index: number`, `'selected' | 'tentatively-selected'`, item
|
|
180
|
+
models). A parameter is optional if it has a default, is checked against `undefined`, or some call
|
|
181
|
+
in the bundle leaves it out. What can't be recovered stays `argN: unknown`. A property is optional if it
|
|
147
182
|
held `undefined` or was added after the calculator loaded (for example, by the first animation frame
|
|
148
183
|
or a UI interaction).
|
|
149
184
|
|