Skip to content

Commit 504aa33

Browse files
committed
Update docs per recent changes
1 parent 6c73ea3 commit 504aa33

4 files changed

Lines changed: 41 additions & 25 deletions

File tree

src/types/ARCHITECTURE.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ How TypeScript types are organized in plotly.js.
88
┌──────────────────────────────────────────────────────────────┐
99
│ Consumer surface (what `npm install plotly.js` exposes) │
1010
│ lib/index.d.ts — wired via package.json#types │
11-
│ Curated re-exports of public types + 'export as namespace │
12-
│ Plotly' for namespace and global usage. │
11+
│ `export type *` for generated schema types + explicit │
12+
│ re-exports of hand-written types + `export as namespace │
13+
│ Plotly` for global/namespace usage. │
1314
└──────────────────────────────────────────────────────────────┘
1415
1516
@@ -23,8 +24,9 @@ How TypeScript types are organized in plotly.js.
2324
│ Hand-written types │ │ Generated types │
2425
│ src/types/core/*.d.ts │ │ src/types/generated/... │
2526
│ src/types/lib/*.d.ts │ │ │
26-
│ │ │ schema.d.ts — from schema │
27-
│ │ │ (traces + layout + shared) │
27+
│ │ │ schema.d.ts — common enums, │
28+
│ │ │ traces, layout, animation, │
29+
│ │ │ config, _internal namespace │
2830
└──────────────────────────┘ └────────────────────────────────┘
2931
```
3032

src/types/CONVERTING_ATTRIBUTES.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,14 @@ the attribute object's runtime shape changed (most often a missed
116116

117117
```bash
118118
git add src/<path>/attributes.ts \
119-
src/<path>/index.js src/<path>/defaults.js # (whichever consumers you updated) \
120-
src/types/core/<file>.d.ts \
121-
src/types/generated/
119+
src/<path>/index.js src/<path>/defaults.js # (whichever consumers you updated)
122120
git commit -m "Convert <component> attributes to TypeScript"
123121
```
124122

125-
The conversion is a single self-contained commit per file.
123+
The conversion is a single self-contained commit per file. There's
124+
nothing to commit under `src/types/` for a correct conversion — the
125+
generated types are byte-identical (which is exactly what
126+
`schema-typegen-diff-check` confirmed in step 6).
126127

127128
## Worked example: modebar
128129

@@ -149,8 +150,8 @@ The schema does not describe these — they remain in `src/types/`:
149150
- **Events** (`PlotMouseEvent`, `LegendClickEvent`, etc.)
150151
- **Public API function signatures** (`Plotly.newPlot`, `relayout`, ...)
151152
- **Internal types** (`FullLayout._modules`, `GraphDiv._fullData`, ...)
152-
- **Utility types** the mapped type bottoms out on (`Color`, `Datum`,
153-
`TypedArray`, `MarkerSymbol`, ...)
153+
- **Utility types** (`Color`, `Datum`, `TypedArray`, `MarkerSymbol`, etc.) —
154+
these are the primitives the generator's emitted types reference.
154155

155156
If you find yourself converting one of these, stop and ask.
156157

@@ -211,5 +212,5 @@ Pick from this priority list. Lower-numbered items are smaller / simpler.
211212
## Working in parallel
212213

213214
Multiple converters can work on different attribute files in parallel.
214-
Merge conflicts are rare and limited to the hand-written type files when
215-
removing types — manual conflict if two converters touch the same file.
215+
Each conversion is self-contained within one component's directory plus
216+
its direct `require()`-callers, so merge conflicts are rare.

src/types/GENERATOR.md

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ Run via `npm run schema`.
2121
`tasks/generate_schema_types.mjs` is called by `tasks/schema.mjs` after
2222
writing `plot-schema.json`. The generator walks `schema.traces`,
2323
`schema.layout.layoutAttributes`, `schema.animation`, `schema.frames`, and
24-
`schema.config.edits`, mapping each attribute's `valType` metadata to a
25-
TypeScript type.
24+
`schema.config` (including `schema.config.edits`), mapping each attribute's
25+
`valType` metadata to a TypeScript type. The set of meta keys to strip
26+
during emission is read from `schema.defs.metaKeys` so any addition to the
27+
schema's metadata format is picked up automatically.
2628

2729
### Phase 0: Common enum discovery
2830

@@ -109,7 +111,7 @@ The Layout interface includes subplot index signatures:
109111
// etc.
110112
```
111113

112-
### Phase 5: Animation, frame, and edits interfaces
114+
### Phase 5: Animation, frame, edits, and config interfaces
113115

114116
`AnimationOpts` is emitted from `schema.animation` (references the
115117
injected `Transition` and `AnimationFrameOpts` shared types). `Frame` is
@@ -128,6 +130,15 @@ The override mechanism is the `fieldOverrides` param on `attrsToProperties`
128130
schema can't self-reference. `Edits` is emitted from `schema.config.edits`
129131
without overrides (all fields are concrete booleans).
130132

133+
`ConfigBase` is emitted from `schema.config` after registering Edits'
134+
fingerprint in `sharedTypes`, so `edits?: Edits` references the named
135+
interface rather than re-inlining the subtree. Seven config fields whose
136+
schema `valType` is `any` (`locales`, `modeBarButtons`,
137+
`modeBarButtonsToAdd`, `modeBarButtonsToRemove`, `setBackground`,
138+
`showSources`, `toImageButtonOptions`) come through as `any`; the
139+
hand-written `Config` in `core/config.d.ts` overrides them via
140+
`Omit<ConfigBase, keyof ConfigOverrides> & ConfigOverrides`.
141+
131142
### Phase 6: Internal namespace
132143

133144
Names in `INTERNAL_INTERFACES` are wrapped in `export namespace _internal {
@@ -182,7 +193,7 @@ src/types/generated/schema.d.ts
182193
├── Trace interfaces (ScatterData, BarData, ... — 49 traces)
183194
├── Layout component interfaces (LayoutAxis, Legend, Scene, Annotation, etc.)
184195
├── Layout interface
185-
└── Animation / frames / config (AnimationOpts, Frame, Edits)
196+
└── Animation / frames / config (AnimationOpts, Frame, Edits, ConfigBase)
186197
```
187198

188199
Regenerate with `npm run schema`.
@@ -213,9 +224,10 @@ Attribute name overrides via `ATTR_NAME_OVERRIDES` map specific attribute
213224
paths to a type alias regardless of valType (e.g. `marker.symbol`
214225
`MarkerSymbol`).
215226

216-
Reserved keys stripped from the output: `editType`, `role`, `description`,
217-
`impliedEdits`, `_isSubplotObj`, `_isLinkedToArray`, `_arrayAttrRegexps`,
218-
`_deprecated`.
227+
Reserved keys stripped from the output come from `schema.defs.metaKeys`
228+
currently `editType`, `role`, `description`, `impliedEdits`,
229+
`_isSubplotObj`, `_isLinkedToArray`, `_arrayAttrRegexps`, `_deprecated`.
230+
New additions to that list are picked up automatically on regen.
219231

220232
## Extending the schema generator
221233

@@ -302,18 +314,19 @@ console.log(s.layout.layoutAttributes.xaxis); // inspect layout attrs
302314
console.log(s.traces.scatter.attributes); // inspect trace attrs
303315
```
304316

305-
## Public API re-export check
317+
## Public API re-export
306318

307319
`lib/index.d.ts` uses `export type * from '../src/types/generated/schema'`,
308320
so every top-level exported type from `schema.d.ts` is automatically
309321
re-exported to consumers. Types inside the `_internal` namespace are still
310322
reachable via `_internal.X` (the namespace itself is exported by the
311323
wildcard) but their bare names are not.
312324

313-
`tasks/schema.mjs` short-circuits its per-name re-export verification
314-
when the wildcard is detected. If you ever replace the wildcard with an
315-
explicit allowlist, the per-name check runs and warns about any
316-
exported-but-not-re-exported types.
325+
The wildcard is load-bearing: it removes the maintenance burden of keeping
326+
`lib/index.d.ts` in sync with new schema additions. If anyone ever swaps
327+
it for an explicit allowlist, restore the per-name re-export verifier
328+
that previously lived in `tasks/schema.mjs` (see git history) — otherwise
329+
new generated types will silently fail to surface in the public API.
317330

318331
## CI integration
319332

src/types/SETUP.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Quick reference for the TypeScript toolchain in plotly.js.
2323
- [tsconfig.json](../../tsconfig.json) — type checker config
2424
- [esbuild-config.js](../../esbuild-config.js) — bundler config
2525

26-
Both target ES2016. Strict mode is currently **off** (`strict: false`) for incremental adoption — types tighten over time as files convert.
26+
Both target ES2016. `strict: true` is on in `tsconfig.json` — the type system is fully strict for the `.d.ts` declarations and converted TypeScript sources. The remaining JS files coexist via `allowJs: true` and are type-checked loosely (no strict null checks etc. on the JS side).
2727

2828
## npm scripts
2929

0 commit comments

Comments
 (0)