Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
Copilot wants to merge4 commits intomaster
base:master
Choose a base branch
Loading
fromcopilot/fix-1635

Conversation

Copy link
Contributor

CopilotAI commentedAug 21, 2025
edited
Loading

Template literal types were not inheriting validation tags when intersected with tags likeMaxLength andPattern. This caused validation to pass incorrectly when it should fail.

Problem

Consider this type intersection:

typeTaggedTemplate=tags.MaxLength<10>&tags.Pattern<'^[a-zA-Z0-9_]+$'>&                      `prefix${string}postfix`;consttestValue='prefix;"+,df0123456789postfix';// 28 chars, special characters// Before fix: This would pass validation (incorrect)typia.validate<TaggedTemplate>(testValue);// { success: true }// But regular string with same tags would fail correctlytypia.validate<tags.MaxLength<10>&tags.Pattern<'^[a-zA-Z0-9_]+$'>&string>(testValue);// { success: false, errors: [...] }

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.tags field, unlikecheck_string which processes both type checking and validation tags.

Solution

Modifiedsrc/programmers/internal/check_template.ts to:

  1. Add validation tag processing: Createdcheck_template_type_tags function similar tocheck_string_type_tags
  2. Generate validation conditions: Process tags withvalidate scripts and transpile them to runtime checks
  3. Combine all validations: Return conditions that include template pattern matching AND validation tag checking

Updated call sites inCheckerProgrammer.ts andcheck_dynamic_key.ts to pass the requiredcontext parameter.

After Fix

// Now correctly fails validationtypia.validate<TaggedTemplate>('prefix;"+,df0123456789postfix');// {//   success: false,//   errors: [//     { expected: "string & MaxLength<10>", ... },//     { expected: "string & Pattern<'^[a-zA-Z0-9_]+$'>", ... }//   ]// }// Valid values pass as expectedtypia.validate<TaggedTemplate>('prefix123pos');// { success: true }

The fix ensures template literals validate against:

  1. Template structure (must matchprefix*postfix pattern)
  2. Length constraints (MaxLength<10>)
  3. Pattern constraints (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 moreCopilot coding agent tips in the docs.

…ersection handlerCo-authored-by: samchon <13158709+samchon@users.noreply.github.com>
@socket-security
Copy link

socket-securitybot commentedAug 21, 2025
edited
Loading

Review the following changes in direct dependencies. Learn more aboutSocket for GitHub.

DiffPackageSupply Chain
Security
VulnerabilityQualityMaintenanceLicense
Updated@​types/​body-parser@​1.19.5 ⏵ 1.19.61001006877100
Updated@​types/​express@​4.17.21 ⏵ 4.17.231001006981100
Updated@​typescript-eslint/​parser@​8.30.1 ⏵ 8.40.01001006997+1100
Updated@​types/​autocannon@​7.12.6 ⏵ 7.12.7100+110072+178100
Updated@​types/​inquirer@​8.2.10 ⏵ 8.2.121001007587100
Updatedrollup-plugin-node-externals@​8.0.0 ⏵ 8.0.1100+110010078-3100
Updated@​typescript-eslint/​eslint-plugin@​8.30.1 ⏵ 8.40.099+110078+197+1100
Updated@​types/​node@​22.14.1 ⏵ 18.19.1231001007996100
Updated@​types/​node@​22.14.1 ⏵ 20.19.111001008096100
Updated@​types/​node@​22.14.1 ⏵ 22.17.2100+110080+196100
Updatedclass-validator@​0.14.1 ⏵ 0.14.2100+1100100+180100
Updatedtinyglobby@​0.2.13 ⏵ 0.2.1410010091+183100
Updatedfp-ts@​2.16.10 ⏵ 2.16.1110010010085100
Updatedfastify@​4.29.0 ⏵ 4.29.199+1100+1610092100
Updatedprettier@​3.5.3 ⏵ 3.6.299+110010093100
Updatedzod@​3.24.3 ⏵ 3.25.76100+110010096+2100
Updatedrollup@​4.40.0 ⏵ 4.47.19710010099+2100
Updatedinquirer@​8.2.6 ⏵ 8.2.79910010098100
Updatedopenai@​4.95.1 ⏵ 4.104.099+1100100+1100100

View full report

CopilotAIand others added2 commitsAugust 21, 2025 23:36
…g to check_templateCo-authored-by: samchon <13158709+samchon@users.noreply.github.com>
Co-authored-by: samchon <13158709+samchon@users.noreply.github.com>
CopilotAI changed the title[WIP] typia tags failed on template literal typesFix template literal validation tag inheritance in type checkingAug 21, 2025
CopilotAI requested a review fromsamchonAugust 21, 2025 23:39
Copilot finished work on behalf ofsamchonAugust 21, 2025 23:39
@samchonsamchon reopened thisAug 22, 2025
@pkg-pr-new
Copy link

Open in StackBlitz

npm i https://pkg.pr.new/typia@1656

commit:1891b30

Copy link

@Mlocik97Mlocik97 left a 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.

Comment on lines +71 to +74
.map((row)=>row.filter((tag)=>!!tag.validate))
.filter((row)=>!!row.length)
.map((row)=>
row.map((tag)=>({
Copy link

@Mlocik97Mlocik97Oct 28, 2025
edited
Loading

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.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@samchonsamchonAwaiting requested review from samchon

1 more reviewer

@Mlocik97Mlocik97Mlocik97 requested changes

Reviewers whose approvals may not affect merge requirements

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

typia tags failed on template literal types

3 participants

@Mlocik97@samchon

[8]ページ先頭

©2009-2025 Movatter.jp