-
-
Notifications
You must be signed in to change notification settings - Fork 191
Fix template literal validation tag inheritance in type checking #1656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…ersection handler Co-authored-by: samchon <[email protected]>
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
…g to check_template Co-authored-by: samchon <[email protected]>
Co-authored-by: samchon <[email protected]>
commit: |
Mlocik97
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4 .map and .filter loops instead of one reduce? I think we can optimize this.
| .map((row) => row.filter((tag) => !!tag.validate)) | ||
| .filter((row) => !!row.length) | ||
| .map((row) => | ||
| row.map((tag) => ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot let's replace this with one single reduce loop.
Template literal types were not inheriting validation tags when intersected with tags like
MaxLengthandPattern. This caused validation to pass incorrectly when it should fail.Problem
Consider this type intersection:
The issue affected all validation functions:
validate,assert,is, and schema generation.Root Cause
The intersection handler correctly processed validation tags and attached them to template literal metadata. However, the code generator for templates (
check_template) was only generating pattern matching code and ignoring thetpl.tagsfield, unlikecheck_stringwhich processes both type checking and validation tags.Solution
Modified
src/programmers/internal/check_template.tsto:check_template_type_tagsfunction similar tocheck_string_type_tagsvalidatescripts and transpile them to runtime checksUpdated call sites in
CheckerProgrammer.tsandcheck_dynamic_key.tsto pass the requiredcontextparameter.After Fix
The fix ensures template literals validate against:
prefix*postfixpattern)MaxLength<10>)Pattern<'^[a-zA-Z0-9_]+$'>)Fixes #1635.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.