a2ui-project / a2ui-project/a2ui

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

Abierto
#1,511 1 comentario 0 reacciones 1 asignado Asignado a @andrewkolos Ver en GitHub
other renderers P2 type: feature/enhancement
Lenguaje dominante
TypeScript
Estrellas
16.4k
Forks
1.3k
Merge medio
2 d 13 h
PR fusionados (30 d)
134

Descripción

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

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

The issue is about tightening TypeScript types for ChildList rendering in web_core. Start by examining generic-binder.ts to understand ResolveA2uiProp. Then look at the React ChildList.tsx and Lit List.ts files to see how they currently handle the any/unknown types. The fix involves defining ResolvedChildRef and updating the type resolution. Run the existing tests to ensure changes don't break anything.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
typescript
Área
frontend
Tipo de issue
Refactorización
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Tranquilo
Claridad
Bien especificado
Aptitud para principiantes
65/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.