Fix template literal validation tag inheritance in type checking#1656
Draft
Fix template literal validation tag inheritance in type checking#1656
Conversation
…ersection handler Co-authored-by: samchon <13158709+samchon@users.noreply.github.com>
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
…g to check_template Co-authored-by: samchon <13158709+samchon@users.noreply.github.com>
Co-authored-by: samchon <13158709+samchon@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] typia tags failed on template literal types
Fix template literal validation tag inheritance in type checking
Aug 21, 2025
commit: |
Mlocik97
reviewed
Sep 30, 2025
Mlocik97
left a comment
There was a problem hiding this comment.
4 .map and .filter loops instead of one reduce? I think we can optimize this.
Mlocik97
suggested changes
Oct 28, 2025
Comment on lines
+71
to
+74
| .map((row) => row.filter((tag) => !!tag.validate)) | ||
| .filter((row) => !!row.length) | ||
| .map((row) => | ||
| row.map((tag) => ({ |
There was a problem hiding this comment.
@copilot let's replace this with one single reduce loop.
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.
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.