Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

Commit caf477f

Browse files
claude[bot]claude
andauthored
feat(types): refuse chartType on a chart series by name, pointing at type (#7737)
* feat(types): refuse `chartType` on a chart series by name, pointing at `type` `ChartDataSeriesSchema` is a non-strict `z.object`, so an authored series `chartType` — the renderer's INTERNAL spelling of the declared `type`, the first limb of `normalizeSeries`' `str(raw.chartType) ?? str(raw.type)` — was stripped in silence while `safeParse` reported success. It is now declared as a named ALIAS REFUSAL arm (`aliasKeyRefusal()` in `zod/tombstone.zod.ts`, reusing `retirementTombstone`'s `z.never` primitive so `z.toJSONSchema` keeps working) that answers with the spec's own sentence — "Unrecognized key(s) on this chart series: `chartType`. Did you mean `chartType` → `type`?" — and the TS twin carries a `?: never` tombstone. Both-written is refused, not folded. Re-measured at implementation time, series-level, lit controls: docs 0, fixtures 0, designer inputs 0, src literals 0, tests 9 (internal-shape). Limb ablation over 304 files / 5817 tests: deleting the `chartType` limb left all green; deleting the `type` sibling went 2 red. No reader changed. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KbJQ1y1J12nZxYzFWhP8Q3 * docs(types): correct the alias-refusal rationale and derive pin (e) from the spec's live lead Land-prep for PR #7737, asked for by its contract review (VERDICT: PASS, not withdrawn). Text and one assertion only — no runtime or type behaviour moves. - `tombstone.zod.ts`: the `aliasKeyRefusal` docblock argued that a census of `retirementTombstone(` sites is a census of keys the contract once declared. Re-measured on this merged head, that partition is false: `MenuItemSchema.type` (`overlay.zod.ts:196`, objectui#6523) is a `retirementTombstone` whose own guidance reads "`type` ('separator' or 'label') was an undeclared spelling two renderers used to read and is now a declared refusal, not a strip", and `overlay.ts:458-464` states it again ("a spelling the type never declared"). The docblock now cites that precedent and names the real differentiator — the composed spec sentence: a vocabulary, not a shape. - pin block (e): it compared ours and the spec's message each to a constant and never to each other, so a spec reword of the lead would have left both green while the faces diverged. The expected lead is now derived from the installed spec's live message at assert time, guarded so the cut still contains the remedy. The cut is unchanged — lead + `Did you mean …?`, excluding the spec's trailing clause (91 bytes, byte-equal to ours on 17.2.0). - changeset: names the parents the narrowing propagates through (`ChartSchema.series`, `ReportSectionSchema.chart`, reached via `safeValidateSchema` and `objectui check` / `validate`) and the io-mode nuance — `io:'input'` narrows; `io:'output'` already emitted `additionalProperties: false` on the base. Both measured on this head. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KbJQ1y1J12nZxYzFWhP8Q3 --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 83c77dc commit caf477f

8 files changed

Lines changed: 532 additions & 36 deletions

File tree

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
'@object-ui/types': minor
3+
---
4+
5+
`ChartDataSeriesSchema` (and its TS twin `ChartDataSeries`) now REFUSES `chartType` on a chart
6+
series BY NAME and points at `type` — the renderer-internal spelling the non-strict Zod object had
7+
been **stripping in silence** while `safeParse` reported success (objectui#7694, the `domain:ui` PM
8+
ruling on objectui#7546: option A, a named alias refusal, the posture `@objectstack/spec` already
9+
takes).
10+
11+
⚠️ Shipped as `minor`, not `patch`, because this is a NARROWING of a published accept surface, and
12+
it is named here in the words a release reader can act on:
13+
14+
- **Before:** `series: [{ name: 'revenue', chartType: 'line' }]` validated green through
15+
`@object-ui/types/zod` (`safeValidateSchema`, `objectui check` / `objectui validate`, any
16+
pipeline that keeps `parse()`'s output) — and the key was gone from the output, so a consumer of
17+
the parse result drew that series in the chart's own family, precisely what the author was
18+
overriding. On the TypeScript face the key was merely an excess property on a fresh literal;
19+
a widened object carrying it assigned structurally.
20+
- **After:** the same document REFUSES at `series[i].chartType` (issue code `invalid_type`) with
21+
one message on both channels — the parse-time issue and the `.describe()` metadata:
22+
`Unrecognized key(s) on this chart series: \`chartType\`. Did you mean \`chartType\` → \`type\`? …`
23+
followed by the reason and the remedy. Write `type: 'bar' | 'line' | 'area'`. On the TypeScript
24+
face `ChartDataSeries.chartType` is a `?: never` tombstone, so both the fresh literal and the
25+
widened assignment are `tsc` errors.
26+
- **Both written** (`{ type: 'bar', chartType: 'line' }`) is refused at `chartType` alone — the
27+
key is not folded onto `type` and no precedence is minted between the two spellings.
28+
- **Which documents to scan.** The narrowing does not stop at `ChartDataSeriesSchema`; it reaches
29+
every document through the parents that embed it — `ChartSchema.series`
30+
(`zod/data-display.zod.ts:622`, `z.array(ChartDataSeriesSchema)`) and, one level further out,
31+
`ReportSectionSchema.chart` (`zod/reports.zod.ts:105`, `ChartSchema.optional()`). Authors meet it
32+
through `safeValidateSchema()` (`zod/index.zod.ts:434`, which parses `AnyComponentSchema`) and
33+
through the CLI's `objectui check` and `objectui validate` commands (`packages/cli/src/cli.ts:211`
34+
and `:223`). In practice: every `chart` node's `series[]`, and every report section whose `chart`
35+
carries one.
36+
37+
This repository's `major` is a cross-repo pin to `@objectstack`'s major, not a severity dial; the
38+
break is announced here, which is the channel that carries it.
39+
40+
## Why a refusal, and not the two alternatives
41+
42+
`chartType` is the renderer's INTERNAL spelling of `type`: the first limb of `normalizeSeries`'
43+
`str(raw.chartType) ?? str(raw.type)` (`@object-ui/plugin-charts`, `normalizeChartSchema.ts:244`),
44+
written by the internal-shape producers that hand `dataKey`-shaped arrays straight to
45+
`ChartRenderer` (`ObjectChart`, `DatasetWidget`; `core/utils/chart-presentation` translates authored
46+
`type` *into* it) and by nothing an author writes. Re-measured at implementation time, series-level,
47+
with lit controls (`dataKey` / `name` / `type` / `color`): docs 0, fixtures 0, designer inputs 0
48+
(the `chart` registration's `series` is one `code` input), src literals 0, tests 9 — every one an
49+
internal-shape array that never meets this mirror. Limb ablation over 304 files / 5817 tests:
50+
deleting `str(raw.chartType) ??` left all green; deleting the `?? str(raw.type)` sibling went 2 red.
51+
52+
- **Not a fold onto `type`.** The renderer takes `chartType` FIRST, so a fold would let the alias
53+
overwrite the canonical key when both are written — the inversion of the objectui#7113 precedence
54+
rule (`xAxis` → `xAxisKey` folds *because* the reader already prefers the canonical key).
55+
- **Not a second writable name.** `@objectstack/spec`'s `ChartSeriesSchema` lists `chartType` in its
56+
alias map as a spelling of `type` and refuses it by name; declaring it here would mint a second
57+
de-facto contract against the spec's own posture (AGENTS.md #0.1).
58+
59+
## The primitive, and the JSON-Schema surface
60+
61+
The new `aliasKeyRefusal()` helper (`zod/tombstone.zod.ts`, internal — not re-exported) reuses
62+
`retirementTombstone`'s primitive, `z.never({ error }).optional().describe()`, deliberately not
63+
`handlerKeyRefusal`'s `z.custom`: measured, `z.toJSONSchema` throws on a `z.custom` arm ("Custom
64+
types cannot be represented in JSON Schema") and represents a `z.never` arm as `{ not: {} }` with its
65+
description. `z.toJSONSchema(ChartDataSeriesSchema)` succeeded before this change and still does —
66+
it now lists `chartType` as a refused property carrying the guidance, 11 properties to 12.
67+
68+
⚠️ The two io modes are not affected alike, measured on this tree. In `io: 'input'` the emitted
69+
object carries no `additionalProperties` at all, so the accept set genuinely narrows there:
70+
`chartType` goes from unmentioned to a property that nothing satisfies. In `io: 'output'` — the
71+
default, and what a bare `z.toJSONSchema(…)` emits — the base **already** emitted
72+
`additionalProperties: false`, so the key was outside the accept set before this change; what that
73+
mode gains is the NAMED refusal and its guidance, not a narrower accept set.
74+
75+
## Unchanged, deliberately
76+
77+
The object stays non-strict — a truly undeclared key is still stripped, exactly as
78+
`chart-inline-data-retired.test.ts` pins. The six keys objectui#7546 declared, the `data` tombstone
79+
(objectui#6896) and the at-least-one-binding refinement (objectui#6939 / #7113) are untouched.
80+
**No reader changed:** `normalizeSeries` still reads `chartType` first on the internal-shape arrays
81+
its producers hand it; that limb is a reader decision, not this declaration's.
82+
83+
## FROM → TO
84+
85+
```ts
86+
// ChartDataSeries
87+
+ chartType?: never; // alias of `type` — refused by name; write `type`
88+
```
89+
90+
Pinned in `packages/types/src/__tests__/chart-series-chart-type-alias-refusal-7694.test.ts` —
91+
the refusal envelope, both-written, the TS face, the spec's own posture measured live on the
92+
installed `@objectstack/spec`, and the JSON-Schema surface; `chart-series-keys-7546.test.ts` block
93+
(d) now pins the handoff from the gap that card reported.

‎content/docs/api/schema-reference.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ numbers of its own: `ChartDataSeries.data` is a retirement tombstone
491491
| `title` | `string` | Chart title. |
492492
| `description` | `string` | Chart description / subtitle. |
493493
| `categories` | `string[]` | An **alternative series list** — column names to plot, read only when `series` is absent, and ignored outright when it is present. Not axis labels: the category axis comes from `xAxisKey`. |
494-
| `series` | `ChartDataSeries[]` | Data series. Each entry's `name` (or `dataKey`) names the column it plots within a `data` row; optional `label`, `color`, a per-series `type` (`"bar"`, `"line"`, `"area"`) for combo charts, `stack`, `yAxis` (`"left"` / `"right"`), `variant` (`"primary"` / `"comparison"`), `dashArray` and `opacity`. |
494+
| `series` | `ChartDataSeries[]` | Data series. Each entry's `name` (or `dataKey`) names the column it plots within a `data` row; optional `label`, `color`, a per-series `type` (`"bar"`, `"line"`, `"area"`) for combo charts, `stack`, `yAxis` (`"left"` / `"right"`), `variant` (`"primary"` / `"comparison"`), `dashArray` and `opacity`. `chartType` on a series is refused by name — it is the renderer's internal spelling of `type`; write `type`. |
495495
| `data` | `Array<Record<string, any>>` | Rows to plot — one object per row, keyed by column name. |
496496
| `xAxisKey` | `string` | Row key holding the category (x) axis. The bare-string `xAxis: "month"` spelling folds onto this key at parse. |
497497
| `height` / `width` | `string \| number` | Chart dimensions. |

‎content/docs/plugins/plugin-charts.mdx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ Each `series` entry names the column it plots (`dataKey`, or the spec spelling `
193193
| `dashArray` | `string` | SVG `stroke-dasharray`, e.g. `"4 4"` for a dashed line. Today the renderer applies it only on a `variant: 'comparison'` series **and** only on a mark that has a stroke to dash — a `line` or `area` mark (the chart's `chartType`, or a per-series `type` override), where it overrides the overlay's default `"4 4"`; a comparison `bar` or `scatter` mark takes `opacity` only and drops the dash, and on a primary series of any family it is read and unused. |
194194
| `opacity` | `number` | Stroke and fill opacity override — any finite number (the spec bounds it to 0–1). Today the renderer applies it only on a `variant: 'comparison'` series, where it overrides the overlay's per-family default on every mark family — the fill of a `bar` or `scatter` mark, the stroke of a `line` mark, both on an `area` mark; on a primary series it is read and unused. |
195195

196+
`chartType` is **not** a series key. It is the renderer's internal spelling of `type` — `@objectstack/spec`'s `ChartSeries` lists it as an alias — and the validator refuses it by name (`Unrecognized key(s) on this chart series: chartType. Did you mean chartType → type?`) instead of dropping it silently, which is what it used to do. Write `type`.
197+
196198
An `area` chart keeps every key in this example live: `stack` stacks the two primary areas, and the comparison overlay takes both the dash and the opacity (on a `bar` chart the overlay would take `opacity` only).
197199

198200
```tsx

0 commit comments

Comments
 (0)