Skip to content

Commit 1db7745

Browse files
committed
Fix algorithm
1 parent f427902 commit 1db7745

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/compiler/checker.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22914,10 +22914,15 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2291422914
}
2291522915

2291622916
if (source.flags & TypeFlags.TemplateLiteral && target.flags & TypeFlags.StringLike) {
22917-
(source as TemplateLiteralType).types = (source as TemplateLiteralType).types.flatMap(type => {
22918-
return type.flags & TypeFlags.Intersection ? (type as IntersectionType).types.filter(t => t.flags & TypeFlags.Primitive) : [type]
22917+
const resolvedPrimitiveTypes = (source as TemplateLiteralType).types.flatMap(type => {
22918+
if (type.flags & TypeFlags.Intersection && (type as IntersectionType).types.every(type => type.flags & TypeFlags.Primitive || type.flags & TypeFlags.Object)) {
22919+
return (type as IntersectionType).types.filter(t => t.flags & TypeFlags.Primitive)
22920+
} else {
22921+
return [type]
22922+
}
2291922923
});
22920-
return isRelatedTo(source, target, RecursionFlags.Both, /*reportErrors*/ false);
22924+
22925+
(source as TemplateLiteralType).types = resolvedPrimitiveTypes;
2292122926
}
2292222927

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

0 commit comments

Comments
 (0)