fix: add type checking for optional properties#53
Open
Shubh-Raj wants to merge 1 commit intoaccordproject:mainfrom
Open
fix: add type checking for optional properties#53Shubh-Raj wants to merge 1 commit intoaccordproject:mainfrom
Shubh-Raj wants to merge 1 commit intoaccordproject:mainfrom
Conversation
2 tasks
cb71565 to
dd49484
Compare
mttrbrts
requested changes
Jan 8, 2026
src/TemplateMarkInterpreter.ts
Outdated
| if (OPTIONAL_DEFINITION_RE.test(node.$class) || | ||
| CONDITIONAL_DEFINITION_RE.test(node.$class) || | ||
| WITH_DEFINITION_RE.test(node.$class)) { | ||
| if (node.name) { |
Member
There was a problem hiding this comment.
Under what scenario does a node not have a name property? If there is no scenario, and we have checks elsewhere, let's remove this condition.
Contributor
Author
There was a problem hiding this comment.
You're right — there's no such scenario. name is a required field on IElementDefinition, which IOptionalDefinition, IConditionalDefinition, and IWithDefinition all extend. Removed the unnecessary check in 3f9a552.
Signed-off-by: Shubh-Raj <shubhraj625@gmail.com>
dd49484 to
3f9a552
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
.errorsproperty for structured accesstest/templates/bad/optional-noguard/Testing
All 26 TemplateMarkInterpreter tests pass. All 33 snapshots pass.
Related Issues
Fixes accordproject/template-playground#11