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

Commit aa6be30

Browse files
feat(plugin-charts): the dataKey arm of ChartRendererProps.series declares type (objectui#8086) (#10554)
Fixes #8086 Clause-②: yes A published TS union widens to what `ChartDataSeriesSchema` and the renderer already accept. This executes ruling `5809905710` (align) on objectui#8086, dispatched by the `domain:ui` seat 2 (claim comment `5828875764`). ## What changed - `packages/plugin-charts/src/ChartRenderer.tsx`: the `dataKey` arm of `ChartRendererProps.schema.series` gains `type?: string`, the same member type the `name` arm declares. No other member of either arm changes. The docblock that PR #8080 added ("This TS union stays as declared …") is replaced by the aligned statement. The component-body comment said `normalizeSeries` round-trips "every key the internal arm declares" unchanged. That comment is updated for the new member, because `type` is translated to `chartType` and not passed through. - `ChartRenderer.specSeries.test.tsx`: the `as any` on the `{ dataKey, type }` case is removed. The one other `as any`, on the `categories` case, stays, and a comment now gives the reason: it covers `categories`, which `ChartRendererProps.schema` does not declare. Leg B below measures this. - `ChartRenderer.seriesTypeArm-8086.test.ts` (new, in the same folder): compile-time pins against each arm. - `packages/types/src/objectql.ts`: a prose-only change. The `ObjectChartSchema.series` docblock said its element type is the internal arm "VERBATIM". After this change that arm carries `type` and the copy does not, so the sentence is rewritten. The type itself is unchanged. See Deviations. - `.changeset/8086-chart-series-type-arm.md`: `'@object-ui/plugin-charts': minor`. ## Premise measurement: the old `as any` was not needed `series` is a union with no literal discriminant. TypeScript's excess-property check on an object literal therefore only asks whether each key is known to at least one arm. On the base declaration, the specSeries literal with `{ dataKey: 'margin', type: 'line' }` compiles without the cast, because `type` is known to the `name` arm. Leg A shows this: with the cast already removed, `ChartRenderer.specSeries.test.tsx` reports zero errors. For the same reason, a `{ name, chartType }` literal compiles against the whole union on both base and head, because `chartType` is known to the `dataKey` arm. The gap the card names is real, but it is in the arm, not the union. On base, a value typed as the `dataKey` arm cannot carry `type` (TS2353), and an entry narrowed with `'dataKey' in entry` cannot read it (TS2339). So each new pin is written against a single arm, the `Extract` of the union on its binding key. Pins written against the whole union would pass on both sides of the change. ## Evidence (HEAD `ff726c28c`) **Red on base (leg A).** This leg removes only the new member from `ChartRenderer.tsx`, which restores the base declaration, and keeps every test at HEAD. The edit went through `node ../objectstack/scripts/ablation-replace.mjs`: the anchor went from 1 hit to 0, the blob changed from `e0dac80c6e03` to `ad7bb3165aac`, and after restore the blob matched HEAD and `git diff HEAD` was empty. It then ran `tsc -p tsconfig.test.json --listFiles` in `packages/plugin-charts`. The file list includes `ChartRenderer.tsx`, `ChartRenderer.seriesTypeArm-8086.test.ts` and `ChartRenderer.specSeries.test.tsx`. Line and column numbers are removed from the output below: ```text ChartRenderer.seriesTypeArm-8086.test.ts TS2339 Property 'type' does not exist on type '{ dataKey: string; ... }' (the Equal pin) ChartRenderer.seriesTypeArm-8086.test.ts TS2353 'type' does not exist in type '{ dataKey: string; ... }' (value typed as the dataKey arm) ChartRenderer.seriesTypeArm-8086.test.ts TS2339 Property 'type' does not exist on type '{ dataKey: string; ... }' (reading it back) ChartRenderer.seriesTypeArm-8086.test.ts TS2339 Property 'type' does not exist on type '{ dataKey: string; ... }' (read after narrowing with 'dataKey' in e) TSC_EXIT=2 ``` Leg A also reports no error in `ChartRenderer.specSeries.test.tsx`, which is the premise measurement above. The control `@ts-expect-error` raised no TS2578, so a `{ name, chartType }` value typed as the `name` arm is refused on base, as it is on head. **Green on head.** `pnpm run type-check` in `packages/plugin-charts` (`tsc --noEmit && tsc -p tsconfig.test.json`) printed `VERDICT command-exit 0`. **Kept cast (leg B).** With the `as any` removed from the `categories` case at HEAD, tsc reports `ChartRenderer.specSeries.test.tsx TS2353: Object literal may only specify known properties, and 'categories' does not exist in type '{ type: string; ... }'` and `TSC_EXIT=2`. After restore, the blob matched HEAD. **Tests** (repo-root form, through the shared verify lock): - `pnpm exec vitest run --maxWorkers=2 packages/plugin-charts/`: `Test Files 73 passed (73)`, `Tests 831 passed (831)`. - `pnpm exec vitest run --reporter=verbose` on the two touched test files: 2 files, 9 tests passed, 3 of them in the new pin file. - `pnpm run type-check` in `packages/types`: exit 0. - `pnpm exec vitest run --maxWorkers=2 packages/types/`: `Test Files 233 passed (233)`, `Tests 5184 passed (5184)`. **Gates** (verdict lines as printed): - `node scripts/check-changeset-presence.mjs`: `✅ 4 source file(s) of 2 released package(s) changed, and this change declares 1 changeset(s)`. - `check-changeset-no-major` ✅, `check-changeset-overwrite` ✅, `check-changeset-fixed` ✅, `check-changeset-claims`: both sections PASS. - `pnpm check:new-line-citations`: `VERDICT new-cross-file-line-citations: 0 new citation(s)`. - `pnpm check:control-bytes`: `✅ check-control-bytes: OK`. - `check:pending-changeset-literals`, `check:test-path-roots`, `check-vi-mock-specifiers` / `-inherit` / `-override-shape`, `check-type-check-coverage` (43/43), `check:published-tsconfig-exclude` and `check:unreferenced-sources`: all OK. - `node scripts/check-governed-queue-guard.mjs --test` on the five paths: `NOT GOVERNED`. - Lint was scoped to the four touched source files, with three pieces of evidence that the scoping skips nothing. First, `eslint --print-config` finds the root `eslint.config.js` for each file (117 to 118 rules), so none is ignored. Second, `--format json` shows 4 files and 0 errors; the only warnings are the existing `no-explicit-any` ones, and the specSeries file has one fewer than on base. Third, `eslint.config.js` has no `parserOptions.project` or `projectService`, so type-aware linting is off, and no local rule under `eslint-rules/` reads the filesystem. This diff therefore cannot change the lint result of any file it does not touch. The full `pnpm lint` runs in CI. - Doc and README gates: not reached. The diff touches no doc, README or doc fence, and the charts doc already lists `type` as a per-series key for either binding. ## Deviations 1. **File surface.** The claim listed `ChartRenderer.tsx` (only the `dataKey` arm and the docblock), the specSeries test with a pin next to it, and the changeset. Two edits fall outside that list. Both are prose that this change would otherwise leave false: - the component-body comment in `ChartRenderer.tsx` (same file, but not the docblock); - the `ObjectChartSchema.series` docblock in `packages/types/src/objectql.ts` (the "VERBATIM" claim). The dispatch order says to stop on a breach. The os-dev role file says published text that the change makes false must be fixed, and that the role file wins when the two conflict. So both edits are made and listed here. The claim's file surface needs the seat to add them. If the seat wants them out, removing those two hunks is enough, and the type change does not depend on them. 2. **Commit trailer.** Commit `ff726c28c` ends with the harness-supplied `Co-Authored-By` trailer, which names the model, instead of the model-free pair. History is not rewritten, because force-push is banned here. ## Acceptance notes - `ChartRendererProps` is not re-exported by name from the `@object-ui/plugin-charts` entry. Consumers reach it as the props type of the exported `ChartRenderer`. In the published 17.6.0 dist it is declared in `dist/ChartRenderer.d.ts` and used by the registry map type in `dist/index.d.ts`, and its `dataKey` arm has no `type`. The runtime half, objectui#7681, is still a pending changeset, so the declaration and the behaviour ship in the same release. - `ObjectChartSchema.series` in `@object-ui/types` (the TS interface and its zod mirror) is a copy of the internal arm and does not have `type`. Whether that published copy should follow is a separate Clause-② decision that this PR does not take. Carrier: none. - A comment in `widget-schema-anchors-7946.test.ts` says `series`' element type "is" the internal arm. Its assertion only pins `dataKey: string`, which still holds. The comment is test-only and not published, so it is left unchanged. - The `series` union has no literal discriminant, so object literals get union-wide excess-property checks, and a `{ name, chartType }` literal type-checks against the union. This PR leaves that as it is, because the ruling allows no other arm change. --- _Generated by [Claude Code](https://claude.ai/code/session_014mXUNuFomfj24w7s1pZzhN)_ Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4f74cd5 commit aa6be30

5 files changed

Lines changed: 117 additions & 20 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
'@object-ui/plugin-charts': minor
3+
---
4+
5+
`ChartRendererProps.schema.series`: the `dataKey` arm now declares `type?: string`, the
6+
per-series family override the `name` arm already declares, with the same member type
7+
(objectui#8086). The TypeScript face now states what `ChartDataSeriesSchema` (where
8+
`dataKey` and `name` are each independently optional beside `type`) and the renderer
9+
(every entry goes through `normalizeSeries`, objectui#7681) accept. No other arm changes:
10+
`chartType` stays on the `dataKey` arm alone, and wins when an entry writes both.
11+
12+
The accept set only widens. A value typed as the `dataKey` arm may now carry `type`, and
13+
an entry narrowed with `'dataKey' in entry` may read it; nothing that compiled before is
14+
refused. `ChartRendererProps` is not re-exported by name from the package entry: it
15+
reaches consumers as the props type of the exported `ChartRenderer` component. An object
16+
literal written against the whole `series` union was already accepted before this
17+
change, because `type` is known to the `name` arm; the gap was at the arm.
18+
19+
The `ObjectChartSchema.series` docblock in `@object-ui/types` is restated to match: that
20+
copy of the internal arm does not carry `type`, and its type is unchanged.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* objectui#8086 — the `dataKey` arm of `ChartRendererProps.schema.series`
11+
* declares the per-series family override `type`, with the `name` arm's own
12+
* member type.
13+
*
14+
* Ruling (align): the published TS face states what the contract
15+
* (`ChartDataSeriesSchema`, where `dataKey` and `name` are each independently
16+
* optional beside `type`) and the renderer (every entry goes through
17+
* `normalizeSeries`, objectui#7681) already accept. No other arm changes.
18+
*
19+
* ## Why every pin is ARM-level, not union-level
20+
*
21+
* `series` is a union with no literal discriminant, so TypeScript's excess-
22+
* property check on an object literal only asks whether each key is known to
23+
* SOME arm. A `{ dataKey, type }` literal therefore type-checked against the
24+
* whole union before this card too (`type` is known to the `name` arm), and a
25+
* `{ name, chartType }` literal type-checks against it today (`chartType` is
26+
* known to the `dataKey` arm). A union-level assertion would be green on both
27+
* sides of the change and pin nothing. What was missing is the `dataKey` ARM's
28+
* member: a value typed as that arm could not carry `type`, and an entry
29+
* narrowed to it with `'dataKey' in entry` could not read it.
30+
*
31+
* `tsconfig.test.json` compiles this file, so each statement is enforcement:
32+
* without the member, the `Equal` pin and the narrowed read fail (TS2339) and
33+
* the arm-typed literal fails (TS2353); the `@ts-expect-error` fails the build
34+
* (TS2578) the moment its refusal stops happening.
35+
*/
36+
37+
import { describe, it, expect } from 'vitest';
38+
import type { ChartRendererProps } from './ChartRenderer';
39+
40+
type Equal<A, B> =
41+
(<T>() => T extends A ? 1 : 2) extends (<T>() => T extends B ? 1 : 2) ? true : false;
42+
type Expect<T extends true> = T;
43+
44+
type SeriesEntry = NonNullable<ChartRendererProps['schema']['series']>[number];
45+
type DataKeyArm = Extract<SeriesEntry, { dataKey: string }>;
46+
type NameArm = Extract<SeriesEntry, { name: string }>;
47+
48+
/** The ruling's letter: the `dataKey` arm's `type` is the `name` arm's `type`, member for member. */
49+
export type assertionDataKeyArmTypeMatchesNameArm = Expect<Equal<DataKeyArm['type'], NameArm['type']>>;
50+
/** The helper can FAIL — a synthetic control, so a vacuous `Equal` cannot pass this file. */
51+
export type assertionEqualCanFail = Expect<Equal<Equal<NameArm['type'], number | undefined>, false>>;
52+
53+
describe('ChartRendererProps.series — the `dataKey` arm declares `type` (objectui#8086)', () => {
54+
it('accepts `type` on a value typed as the `dataKey` arm', () => {
55+
const entry: DataKeyArm = { dataKey: 'margin', type: 'line' };
56+
expect(entry.type).toBe('line');
57+
});
58+
59+
it('reads `type` off an entry narrowed to the `dataKey` arm', () => {
60+
const familyOf = (e: SeriesEntry): string | undefined => ('dataKey' in e ? e.type : undefined);
61+
expect(familyOf({ dataKey: 'margin', type: 'line' })).toBe('line');
62+
});
63+
64+
it('changes no other arm: the `name` arm still carries no `chartType`', () => {
65+
// @ts-expect-error — `chartType` is the renderer's INTERNAL spelling of `type`; the `name` arm never carried it, and objectui#8086 widened only the `dataKey` arm.
66+
const authored: NameArm = { name: 'margin', chartType: 'line' };
67+
expect(authored.name).toBe('margin');
68+
});
69+
});

‎packages/plugin-charts/src/ChartRenderer.specSeries.test.tsx‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ describe('ChartRenderer — the spec `series` shape', () => {
118118
// `chartType`. An author who wrote the documented `dataKey` binding AND
119119
// the documented `type` override together (both valid independently on
120120
// `ChartDataSeriesSchema`) got neither: predicted/observed 2 bars / 0
121-
// lines before the fix. `type` on a `dataKey` entry is off the
122-
// `ChartRendererProps` TS union (`as any` matches the schema's own
123-
// acceptance, not this internal prop type — see the docblock).
121+
// lines before the fix. The `dataKey` arm of `ChartRendererProps.series`
122+
// declares `type` too (objectui#8086), so this literal is written with no
123+
// cast; the arm-level pin is `ChartRenderer.seriesTypeArm-8086.test.ts`.
124124
const { container } = render(
125125
<ChartRenderer
126126
schema={{
@@ -130,7 +130,7 @@ describe('ChartRenderer — the spec `series` shape', () => {
130130
xAxisKey: 'month',
131131
series: [{ dataKey: 'revenue' }, { dataKey: 'margin', type: 'line' }],
132132
isAnimationActive: false,
133-
} as any}
133+
}}
134134
/>,
135135
);
136136
expect(await plotted(container)).toEqual({ bars: 1, lines: 1 });
@@ -160,7 +160,9 @@ describe('ChartRenderer — the spec `series` shape', () => {
160160
// because `normalizeChartSchema` — the one translation point — has always
161161
// consumed it. The axis is written in the canonical `xAxisKey`: the
162162
// Tremor-ish `index` alias that stood here is retired, and its pin lives in
163-
// `ChartRenderer.foreignDialectRetired-8650.test.tsx`.
163+
// `ChartRenderer.foreignDialectRetired-8650.test.tsx`. The `as any` below
164+
// is for `categories`, which `ChartRendererProps.schema` does not declare;
165+
// it is not a `series` escape (objectui#8086 widened only the `series` arm).
164166
const { container } = render(
165167
<ChartRenderer
166168
schema={{

‎packages/plugin-charts/src/ChartRenderer.tsx‎

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,18 @@ export interface ChartRendererProps {
6262
* blank. `normalizeChartSchema` translates every entry, of either shape,
6363
* uniformly — see the normalization comment in the component body.
6464
*
65-
* This TS union stays as declared (the `dataKey` arm has no `type`, the
66-
* `name` arm has no `chartType`): at RUNTIME `type` is honoured on a
67-
* `dataKey`-shaped entry too (objectui#7681, both keys are independently
68-
* optional on `ChartDataSeriesSchema`), because JSON metadata never goes
69-
* through this TS type. Widening the arm to match is a separate,
70-
* public-face decision this fix does not make.
65+
* Both arms carry the per-series family override `type`, with the same
66+
* member type (objectui#8086): the renderer honours it on either shape,
67+
* because every entry goes through `normalizeSeries` (objectui#7681), and
68+
* `ChartDataSeriesSchema` declares `dataKey` and `name` independently
69+
* optional beside it — so a `dataKey` entry carrying `type` is what the
70+
* contract and the renderer both accept, and this union says so.
71+
* `chartType` stays on the `dataKey` arm alone: it is the renderer's
72+
* INTERNAL spelling of `type`, and it wins when an entry writes both.
73+
* Pinned at compile time in `ChartRenderer.seriesTypeArm-8086.test.ts`.
7174
*/
7275
series?: Array<
73-
| { dataKey: string; label?: string; variant?: 'current' | 'comparison'; opacity?: number; dashArray?: string; chartType?: 'bar' | 'line' | 'area'; stack?: string; yAxis?: 'left' | 'right'; color?: string }
76+
| { dataKey: string; label?: string; type?: string; variant?: 'current' | 'comparison'; opacity?: number; dashArray?: string; chartType?: 'bar' | 'line' | 'area'; stack?: string; yAxis?: 'left' | 'right'; color?: string }
7477
| { name: string; label?: unknown; type?: string; variant?: 'current' | 'comparison' | 'primary'; opacity?: number; dashArray?: string; stack?: string; yAxis?: 'left' | 'right'; color?: string }
7578
>;
7679
/** Spec `ChartConfig` shape — honored via `normalizeChartSchema`
@@ -151,10 +154,12 @@ export const ChartRenderer: React.FC<ChartRendererProps> = ({ schema, onChartCli
151154
// together — both valid on `ChartDataSeriesSchema` independently — got
152155
// NEITHER honoured (objectui#7681).
153156
//
154-
// `normalizeSeries` is a no-op on a well-formed internal-shaped entry: it
155-
// round-trips every key the internal arm of `ChartRendererProps.series`
156-
// declares (`dataKey`/`label`/`chartType`/`variant`/`opacity`/`dashArray`/
157-
// `stack`/`yAxis`/`color`) unchanged. So always taking the normalized array
157+
// `normalizeSeries` is a no-op on a well-formed internal-shaped entry apart
158+
// from `type`: it round-trips every other key the internal arm of
159+
// `ChartRendererProps.series` declares (`dataKey`/`label`/`chartType`/
160+
// `variant`/`opacity`/`dashArray`/`stack`/`yAxis`/`color`) unchanged, and
161+
// translates `type` to `chartType` — the translation this routing exists
162+
// for. So always taking the normalized array
158163
// is not a second read site for `type` (AGENTS.md #0.1) — it is routing
159164
// EVERY entry, of either shape, through the ONE normalization layer
160165
// (objectui#2880 S1) instead of special-casing one shape around it, which

‎packages/types/src/objectql.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4362,10 +4362,11 @@ export interface ObjectChartSchema extends BaseSchema {
43624362
* INTERNAL (relay-composed) — the plotted series, in the renderer's internal
43634363
* `{ dataKey }` contract.
43644364
*
4365-
* The element type is `ChartRendererProps.schema.series`' internal arm
4366-
* VERBATIM — that is the read this value ends at, and the ruling on
4367-
* objectui#7946 asked for the reads rather than a copy of any producer's
4368-
* literal. The spec's AUTHOR-facing `ChartSeriesSchema` is the other arm
4365+
* The element type is `ChartRendererProps.schema.series`' internal arm —
4366+
* that is the read this value ends at, and the ruling on objectui#7946 asked
4367+
* for the reads rather than a copy of any producer's literal — every member
4368+
* of it except `type`, which that arm gained under objectui#8086 and this
4369+
* copy has not taken up. The spec's AUTHOR-facing `ChartSeriesSchema` is the other arm
43694370
* (`{ name }`), and it refuses `dataKey` by name; `normalizeChartSchema` is
43704371
* the one translation between them.
43714372
*/

0 commit comments

Comments
 (0)