a2ui-project / a2ui-project/a2ui

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

Offen
#1,511 1 Kommentar 0 Reaktionen 1 zugewiesene Person Zugewiesen an @andrewkolos Auf GitHub ansehen
other renderers P2 type: feature/enhancement
Vorherrschende Sprache
TypeScript
Sterne
16.4k
Forks
1.3k
Ø Merge
2 T. 13 Std.
Gemergte PRs (30 T.)
134

Beschreibung

[`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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.