a2ui-project / a2ui-project/a2ui

Strict Type Coercion in DataContext

Abierto
#846 5 comentarios 0 reacciones 0 asignados Ver en GitHub
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

# 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`

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.