a2ui-project / a2ui-project/a2ui
Strict Type Coercion in DataContext
- 主要语言
- TypeScript
- 星标
- 16.4k
- 派生
- 1.3k
- 平均合并
- 2 天 13 小时
- 30 天内合并 PR
- 134
描述
# Proposal: Strict Type Coercion in DataContext
## Reason
The A2UI protocol defines standard coercion rules (e.g., `null` resolving to `""` for strings). Without central enforcement, component authors must manually handle these edge cases, leading to bugs like `[object Object]` appearing in text labels.
## Design
1. **Coercion Utils**: Implement the coercion table from the `renderer_guide.md` in a shared utility.
2. **Context Integration**: Update `DataContext.resolveDynamicValue` and `resolveSignal` to apply these rules.
3. **Primitive Safety**:
- String targets: Convert any non-string to localized string; map `null/undefined` to `""`.
- Number targets: Parse strings; map `null/undefined` to `0`.
- Boolean targets: Map `"true"` (case-insensitive) and non-zero numbers to `true`.
4. **GenericBinder Alignment**: Ensure the `GenericBinder` uses these coerced values when populating `ResolvedProps`.
## Key Files
- `renderers/web_core/src/v0_9/rendering/data-context.ts`
- `renderers/web_core/src/v0_9/rendering/generic-binder.ts`
贡献指南
调研方向
Start by reading the coercion table in `renderer_guide.md`. The main files to modify are `renderers/web_core/src/v0_9/rendering/data-context.ts` (specifically the `resolveDynamicValue` and `resolveSignal` methods) and `renderers/web_core/src/v0_9/rendering/generic-binder.ts`. Ensure the new coercion utilities are applied consistently. Test by checking that values like `null` correctly coerce to `""` for strings and `0` for numbers in the UI.
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- backend-api-design
- Issue 类型
- 功能
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 冷清
- 描述清晰度
- 描述清楚
- 新手友好度
- 65/100