Skip to content

Commit 578d8ef

Browse files
committed
Make special intersections order-independent
1 parent d8e81bb commit 578d8ef

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16649,12 +16649,16 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1664916649
return reduceLeft(types, (n, t) => n + getConstituentCount(t), 0);
1665016650
}
1665116651

16652+
function areIntersectedTypesAvoidingPrimitiveReduction(t1: Type, t2: Type) {
16653+
return !!(t1.flags & (TypeFlags.String | TypeFlags.Number | TypeFlags.BigInt)) && t2 === emptyTypeLiteralType;
16654+
}
16655+
1665216656
function getTypeFromIntersectionTypeNode(node: IntersectionTypeNode): Type {
1665316657
const links = getNodeLinks(node);
1665416658
if (!links.resolvedType) {
1665516659
const aliasSymbol = getAliasSymbolForTypeNode(node);
1665616660
const types = map(node.types, getTypeFromTypeNode);
16657-
const noSupertypeReduction = types.length === 2 && !!(types[0].flags & (TypeFlags.String | TypeFlags.Number | TypeFlags.BigInt)) && types[1] === emptyTypeLiteralType;
16661+
const noSupertypeReduction = types.length === 2 && (areIntersectedTypesAvoidingPrimitiveReduction(types[0], types[1]) || areIntersectedTypesAvoidingPrimitiveReduction(types[1], types[0]));
1665816662
links.resolvedType = getIntersectionType(types, aliasSymbol, getTypeArgumentsForAliasSymbol(aliasSymbol), noSupertypeReduction);
1665916663
}
1666016664
return links.resolvedType;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// <reference path="fourslash.ts" />
2+
//
3+
//// declare function a(arg: 'test' | (string & {})): void
4+
//// a('/*1*/')
5+
//// declare function b(arg: 'test' | ({} & string)): void
6+
//// b('/*2*/')
7+
8+
verify.completions({ marker: ["1", "2"], exact: ["test"] });

0 commit comments

Comments
 (0)