Skip to content

Commit 6c73ea3

Browse files
committed
Clarify docs about source of truth
1 parent 6d8db88 commit 6c73ea3

3 files changed

Lines changed: 18 additions & 10 deletions

File tree

src/types/ARCHITECTURE.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@ re-exports.
3636

3737
The split:
3838

39-
- **Generated types** are the single source of truth for everything in
40-
Plotly's attribute schema.
39+
- **Generated types** are the authoritative TypeScript representation of
40+
the runtime schema. The schema itself is produced from Plotly's JS
41+
attribute files (`src/.../attributes.js`), which remain the source of
42+
truth: chain is **attribute files → `plot-schema.json` → generated
43+
types**.
4144
- **`src/types/generated/schema.d.ts`** contains:
4245
- **Common enum aliases** discovered from the schema (Calendar, Dash,
4346
AxisType, PatternShape, XRef, YRef, TransitionEasing, PlotType).

src/types/CONVERTING_ATTRIBUTES.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
# Converting Attribute Files to TypeScript
22

33
This is the **active workflow** for migrating Plotly's `attributes.js` files
4-
to TypeScript. Each conversion turns one attribute file into the single
5-
source of truth for both the runtime schema and the public TypeScript type.
4+
to TypeScript. Attribute files are the source of truth for the runtime
5+
schema; the schema in turn drives the generated public TypeScript types.
6+
Conversion doesn't change that chain — it adds compile-time validation on
7+
top of it.
68

79
## Why
810

9-
Today, attribute metadata lives in `src/.../attributes.js` files and the
10-
matching TypeScript types live separately in `src/types/`. They drift.
11+
Without `as const satisfies AttributeMap`, malformed attribute objects
12+
(missing `valType`, typo'd `values` arrays, wrong `dflt` shape, etc.) only
13+
fail when the runtime tries to use them. Converted attribute files catch
14+
those structural mistakes at TypeScript-compile time, before they ever
15+
reach the schema.
1116

12-
After conversion, the `attributes.ts` file is validated against `AttributeMap`
13-
at compile time, catching structural errors and typos before they reach the
14-
runtime schema.
17+
Conversion is also a small step toward typing the rest of the file (and
18+
eventually the rest of the source tree) in TypeScript, but the immediate
19+
value is the compile-time structural check.
1520

1621
## Recipe
1722

src/types/SETUP.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ npm run typecheck # tsc --noEmit, errors reported, no output
3232
npm run typecheck-watch # incremental rechecking on change
3333

3434
npm run schema # rebuild test/plot-schema.json + regenerate types
35-
npm run schema-typegen-diff-check # regenerate + verify no uncommitted drift in schema.d.ts
35+
npm run schema-typegen-diff-check # regenerate + verify no uncommitted drift in test/plot-schema.json or schema.d.ts
3636
npm run bundle # esbuild → dist/plotly.js
3737
npm run build # full production build
3838
```

0 commit comments

Comments
 (0)