Skip to content

Commit 7a447d7

Browse files
committed
wip: changeset for renderer props index signature narrowing
Claude-Session: https://claude.ai/code/session_01GJjkZ6pmdwWoDYH8fE8FAn Co-authored-by: Claude <noreply@anthropic.com>
1 parent 67418d8 commit 7a447d7

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
'@object-ui/types': patch
3+
'@object-ui/components': patch
4+
---
5+
6+
fix(types,components)!: a renderer's props index signature is `unknown`, not `any`, so a forwarded key must be narrowed before it is used
7+
8+
Clause-②: yes (narrowing)
9+
Metadata-protocol: none
10+
11+
<!-- adr-0087: not-required (type-surface-only ui/packages/types/src/base.ts#ComponentRendererProps) A TypeScript annotation narrowing on a published renderer-props type: no metadata key, accepted value, export or error code is removed or renamed, nothing at runtime changes, and `objectstack migrate meta` has nothing to rewrite. The affected party is a TypeScript consumer, reached by its own compiler. -->
12+
13+
**BREAKING** type-surface narrowing, compile-time only. Nothing a renderer receives or renders at runtime changes.
14+
15+
- **`@object-ui/types`.** `ComponentRendererProps` keeps its index signature, so every key the host forwards is still admitted, but the signature now maps to `unknown` instead of `any`.
16+
- **`@object-ui/components`.** The built-in renderers' own inline props annotations move the same way. The three host keys renderers read by name and pass to their root element (`data-obj-id`, `data-obj-type` and `style`, written or forwarded by `SchemaRenderer`) are declared once in a package-local type instead. The host-supplied callbacks and values a renderer reads by name (`onPageChange` on `pagination`, `onChange` / `value` on `input-otp`, `loading` on `button`, `className` on `text`, react-hook-form's `ref` on the form's built-in controls) are declared on that renderer's props.
17+
18+
**Migration.** A renderer typed with `ComponentRendererProps` that reads a forwarded key:
19+
20+
```ts
21+
// FROM — compiled, because the key was `any`
22+
const Pager = ({ schema, ...props }: ComponentRendererProps<PagerSchema>) =>
23+
<Nav onSelect={(n) => props.onPageChange(n)} />;
24+
25+
// TO — declare the key you read on your own props, or narrow it before use
26+
type PagerProps = ComponentRendererProps<PagerSchema> & { onPageChange?: (page: number) => void };
27+
const Pager = ({ schema, onPageChange }: PagerProps) =>
28+
<Nav onSelect={(n) => onPageChange?.(n)} />;
29+
```
30+
31+
What to do: nothing if your renderers never read a forwarded key off `ComponentRendererProps` without declaring it. Otherwise declare the key on your renderer's props (as above) or narrow the `unknown` value (`typeof x === 'function'`, `typeof x === 'string'`) before using it.

0 commit comments

Comments
 (0)