@@ -404,9 +404,67 @@ export { Button, ButtonConfig } from "./Button";
404404export { FlexBox , FlexBoxConfig } from " ./FlexBox" ;
405405```
406406
407+ ## Typed RenderingContext Usage
408+
409+ RenderingContext uses ` [key: string]: any ` to allow dynamic property access. Parent widgets set context properties that children consume. To add type safety, define typed context interfaces that extend RenderingContext and use them directly in method signatures.
410+
411+ ### Pattern: Typed Method Signatures
412+
413+ Define a typed context interface next to the widget that sets the context properties, then use it in method signatures:
414+
415+ ``` typescript
416+ // In ValidationGroup.ts
417+ import { RenderingContext } from " ../../ui/RenderingContext" ;
418+
419+ /** Typed context interface for form-related context properties */
420+ export interface FormRenderingContext extends RenderingContext {
421+ parentDisabled? : boolean ;
422+ parentReadOnly? : boolean ;
423+ parentViewMode? : boolean | string ;
424+ parentTabOnEnterKey? : boolean ;
425+ parentVisited? : boolean ;
426+ parentStrict? : boolean ;
427+ parentAsterisk? : boolean ;
428+ validation? : { errors: ValidationErrorData [] };
429+ lastFieldId? : string ;
430+ }
431+
432+ export class ValidationGroup extends PureContainerBase <...> {
433+ // Use typed context directly in method signature
434+ explore(context : FormRenderingContext , instance : ValidationGroupInstance ): void {
435+ context .push (" parentStrict" , coalesce (instance .data .strict , context .parentStrict ));
436+ context .push (" parentDisabled" , coalesce (instance .data .disabled , context .parentDisabled ));
437+ super .explore (context , instance );
438+ }
439+ }
440+ ```
441+
442+ ### Existing Typed Contexts
443+
444+ ** FormRenderingContext** (ValidationGroup.ts):
445+ - Used by: ValidationGroup, Field, Label, ValidationError, Button
446+ - Properties: ` parentDisabled ` , ` parentReadOnly ` , ` parentViewMode ` , ` parentTabOnEnterKey ` , ` parentVisited ` , ` parentStrict ` , ` parentAsterisk ` , ` validation ` , ` lastFieldId `
447+
448+ ** SvgRenderingContext** (BoundedObject.ts):
449+ - Used by: Svg, BoundedObject and all SVG components
450+ - Properties: ` parentRect ` , ` inSvg ` , ` addClipRect `
451+
452+ ** ChartRenderingContext** (Chart.ts) - extends SvgRenderingContext:
453+ - Used by: Chart, all chart components (LineGraph, ScatterGraph, Gridlines, Marker, etc.)
454+ - Properties: ` axes ` (Record of axis calculators)
455+
456+ ### Guidelines
457+
458+ 1 . ** Define locally** : Keep context interfaces next to the widgets that define them
459+ 2 . ** Export for consumers** : Export the interface so child widgets can import and use it
460+ 3 . ** Extend appropriately** : ChartRenderingContext extends SvgRenderingContext since charts need ` parentRect `
461+ 4 . ** Use non-null assertion** : When accessing context properties that must exist, use ` context.axes! `
462+
463+ ---
464+
407465## Nice to Have Improvements
408466
409- [ ] Typed RenderingContext usage
467+ [ x ] Typed RenderingContext usage
410468[ ] Better StructuredProp and typed ContentResolver
411469[ ] dropdownOptions might typed as DropdownConfig?
412470[ x] Properly type Component.create, Widget.create, etc.
0 commit comments