Skip to content

Commit

Permalink
Fix algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
horita-yuya committed Feb 13, 2025
1 parent f427902 commit 1db7745
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22914,10 +22914,15 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}

if (source.flags & TypeFlags.TemplateLiteral && target.flags & TypeFlags.StringLike) {
(source as TemplateLiteralType).types = (source as TemplateLiteralType).types.flatMap(type => {
return type.flags & TypeFlags.Intersection ? (type as IntersectionType).types.filter(t => t.flags & TypeFlags.Primitive) : [type]
const resolvedPrimitiveTypes = (source as TemplateLiteralType).types.flatMap(type => {
if (type.flags & TypeFlags.Intersection && (type as IntersectionType).types.every(type => type.flags & TypeFlags.Primitive || type.flags & TypeFlags.Object)) {
return (type as IntersectionType).types.filter(t => t.flags & TypeFlags.Primitive)
} else {
return [type]
}
});
return isRelatedTo(source, target, RecursionFlags.Both, /*reportErrors*/ false);

(source as TemplateLiteralType).types = resolvedPrimitiveTypes;
}

// We limit alias variance probing to only object and conditional types since their alias behavior
Expand Down

0 comments on commit 1db7745

Please sign in to comment.