a2ui-project / a2ui-project/a2ui

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

オープン
#1,511 コメント 1 件 リアクション 0 件 担当者 1 名 @andrewkolos に割り当て済み GitHub で見る
other renderers P2 type: feature/enhancement
主要言語
TypeScript
スター
16.4k
フォーク
1.3k
平均マージ
2日 13時間
マージ済み PR(30日)
134

説明

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

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
frontend
issue の種類
リファクタリング
難易度
3/5
見積もり時間
1〜2日
活発さ
静か
明瞭さ
明確に書かれている
初心者へのやさしさ
65/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。