Skip to content

Conversation

@Shubh-Raj
Copy link

Description

Add compile-time type checking for optional properties in TemplateMark templates. When an optional property is used without a guard ({{#optional}}, {{#if}}, or {{#with}}), the type-checker now throws an error at compile time instead of causing a runtime failure.

Before: Runtime error - "No values found for path '$['last']'"
After: Compile-time error - "Optional properties used without guards: last"

Changes

  • Added validation in checkTypes() to detect unguarded optional property access
  • Uses path-based scoping so guards only apply to descendant nodes
  • Throws proper Error object with .errors property for structured access
  • Added test case test/templates/bad/optional-noguard/

Testing

All 26 TemplateMarkInterpreter tests pass. All 33 snapshots pass.

Related Issues

Fixes accordproject/template-playground#11

Signed-off-by: Shubh-Raj <shubhraj625@gmail.com>
@Shubh-Raj Shubh-Raj force-pushed the shubh-raj/fix/optional-property-typechecking branch from cb71565 to dd49484 Compare January 2, 2026 06:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Type checker doesn't detect usage of optional properties

1 participant