a2ui-project / a2ui-project/a2ui

[web_core] Loose `unknown`/`any` types in basic-catalog `ChildList` rendering

Aperta
#1,511 1 commento 0 reazioni 1 assegnatario Assegnata a @andrewkolos Vedi su GitHub
other renderers P2 type: feature/enhancement
Lingua principale
TypeScript
Stelle
16.4k
Fork
1.3k
Merge medio
2g 13h
PR unite (30g)
134

Descrizione

[`ResolveA2uiProp`](https://github.com/google/A2UI/blob/ade478faf8dcad611b5efb6b864dcbfbc4a51f68/renderers/web_core/src/v0_9/rendering/generic-binder.ts#L130-L131) resolves to `any`, so `props.children` is `any` in every component implementation whose schema uses `ChildListSchema`.

See also https://github.com/google/A2UI/issues/1296. `any`/`unknown` makes code brittle and more cognitively burdensome to reason about. It can even cause LLMs to get confused, e.g. https://github.com/google/A2UI/pull/1510/changes#r3331738566.

Both renderers cast around it locally:

- React's`ChildList.tsx`: accepts `unknown`, later casting each element to `{id: string; basePath?: string}`:
https://github.com/google/A2UI/blob/ade478faf8dcad611b5efb6b864dcbfbc4a51f68/renderers/react/src/v0_9/catalog/basic/components/ChildList.tsx#L21
- Lit's `Row.ts` / `Column.ts` / `List.ts` uses `any`: https://github.com/google/A2UI/blob/ade478faf8dcad611b5efb6b864dcbfbc4a51f68/renderers/lit/src/v0_9/catalogs/basic/components/List.ts#L52

(Angular isn't affected as it rolls its own data binding, not using `GenericBinder` and thus `ResolveA2uiProp`)

## Fix

Define `ResolvedChildRef` and `ResolvedChildList` matching what the binder actually emits:

```ts
export type ResolvedChildRef =
| ComponentId
| {id: ComponentId; basePath: string};
```

Then, we either

1) fix `ResolveA2uiProp`, which is the clean fix but could theoretically break customer builds at the typechecking step:

```diff
export type ResolveA2uiProp = [NonNullable] extends [Action]
? (() => void) | Extract
: [NonNullable] extends [ChildList]
- ? any | Extract
+ ? ResolvedChild[] | Extract
: Exclude extends never
? any
: Exclude;
```
or

2) just define `ResolvedChildRef` within the renders so at least the renderer code is more readable.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.