Skip to content

Commit d8f8b1c

Browse files
committed
Merge branch 'master' into microsoftGH-43213
2 parents 7ed1ba7 + fbc9c94 commit d8f8b1c

16 files changed

+2704
-334
lines changed

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/compiler/checker.ts

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17381,9 +17381,9 @@ namespace ts {
1738117381
(target as UnionType).types.length <= 3 && maybeTypeOfKind(target, TypeFlags.Nullable)) {
1738217382
const nullStrippedTarget = extractTypesOfKind(target, ~TypeFlags.Nullable);
1738317383
if (!(nullStrippedTarget.flags & (TypeFlags.Union | TypeFlags.Never))) {
17384-
if (source === nullStrippedTarget) return Ternary.True;
17385-
target = nullStrippedTarget;
17384+
target = getNormalizedType(nullStrippedTarget, /*writing*/ true);
1738617385
}
17386+
if (source === nullStrippedTarget) return Ternary.True;
1738717387
}
1738817388

1738917389
if (relation === comparableRelation && !(target.flags & TypeFlags.Never) && isSimpleTypeRelatedTo(target, source, relation) ||
@@ -17975,8 +17975,21 @@ namespace ts {
1797517975
if (target.flags & TypeFlags.Intersection) {
1797617976
return typeRelatedToEachType(getRegularTypeOfObjectLiteral(source), target as IntersectionType, reportErrors, IntersectionState.Target);
1797717977
}
17978-
// Source is an intersection. Check to see if any constituents of the intersection are immediately related
17979-
// to the target.
17978+
// Source is an intersection. For the comparable relation, if the target is a primitive type we hoist the
17979+
// constraints of all non-primitive types in the source into a new intersection. We do this because the
17980+
// intersection may further constrain the constraints of the non-primitive types. For example, given a type
17981+
// parameter 'T extends 1 | 2', the intersection 'T & 1' should be reduced to '1' such that it doesn't
17982+
// appear to be comparable to '2'.
17983+
if (relation === comparableRelation && target.flags & TypeFlags.Primitive) {
17984+
const constraints = sameMap((<IntersectionType>source).types, t => t.flags & TypeFlags.Primitive ? t : getBaseConstraintOfType(t) || unknownType);
17985+
if (constraints !== (<IntersectionType>source).types) {
17986+
source = getIntersectionType(constraints);
17987+
if (!(source.flags & TypeFlags.Intersection)) {
17988+
return isRelatedTo(source, target, /*reportErrors*/ false);
17989+
}
17990+
}
17991+
}
17992+
// Check to see if any constituents of the intersection are immediately related to the target.
1798017993
//
1798117994
// Don't report errors though. Checking whether a constituent is related to the source is not actually
1798217995
// useful and leads to some confusing error messages. Instead it is better to let the below checks
@@ -19738,6 +19751,15 @@ namespace ts {
1973819751
return !!(type.flags & TypeFlags.Unit);
1973919752
}
1974019753

19754+
function isUnitLikeType(type: Type): boolean {
19755+
return type.flags & TypeFlags.Intersection ? some((<IntersectionType>type).types, isUnitType) :
19756+
!!(type.flags & TypeFlags.Unit);
19757+
}
19758+
19759+
function extractUnitType(type: Type) {
19760+
return type.flags & TypeFlags.Intersection ? find((<IntersectionType>type).types, isUnitType) || type : type;
19761+
}
19762+
1974119763
function isLiteralType(type: Type): boolean {
1974219764
return type.flags & TypeFlags.Boolean ? true :
1974319765
type.flags & TypeFlags.Union ? type.flags & TypeFlags.EnumLiteral ? true : every((<UnionType>type).types, isUnitType) :
@@ -21721,14 +21743,6 @@ namespace ts {
2172121743
return declaredType;
2172221744
}
2172321745

21724-
function getTypeFactsOfTypes(types: Type[]): TypeFacts {
21725-
let result: TypeFacts = TypeFacts.None;
21726-
for (const t of types) {
21727-
result |= getTypeFacts(t);
21728-
}
21729-
return result;
21730-
}
21731-
2173221746
function isFunctionObjectType(type: ObjectType): boolean {
2173321747
// We do a quick check for a "bind" property before performing the more expensive subtype
2173421748
// check. This gives us a quicker out in the common case where an object type is not a function.
@@ -21800,8 +21814,11 @@ namespace ts {
2180021814
return !isPatternLiteralType(type) ? getTypeFacts(getBaseConstraintOfType(type) || unknownType) :
2180121815
strictNullChecks ? TypeFacts.NonEmptyStringStrictFacts : TypeFacts.NonEmptyStringFacts;
2180221816
}
21803-
if (flags & TypeFlags.UnionOrIntersection) {
21804-
return getTypeFactsOfTypes((<UnionOrIntersectionType>type).types);
21817+
if (flags & TypeFlags.Union) {
21818+
return reduceLeft((<UnionType>type).types, (facts, t) => facts | getTypeFacts(t), TypeFacts.None);
21819+
}
21820+
if (flags & TypeFlags.Intersection) {
21821+
return reduceLeft((<UnionType>type).types, (facts, t) => facts & getTypeFacts(t), TypeFacts.All);
2180521822
}
2180621823
return TypeFacts.All;
2180721824
}
@@ -23134,8 +23151,7 @@ namespace ts {
2313423151
return replacePrimitivesWithLiterals(filterType(type, filterFn), valueType);
2313523152
}
2313623153
if (isUnitType(valueType)) {
23137-
const regularType = getRegularTypeOfLiteralType(valueType);
23138-
return filterType(type, t => isUnitType(t) ? !areTypesComparable(t, valueType) : getRegularTypeOfLiteralType(t) !== regularType);
23154+
return filterType(type, t => !(isUnitLikeType(t) && areTypesComparable(t, valueType)));
2313923155
}
2314023156
return type;
2314123157
}
@@ -23217,7 +23233,7 @@ namespace ts {
2321723233
if (!hasDefaultClause) {
2321823234
return caseType;
2321923235
}
23220-
const defaultType = filterType(type, t => !(isUnitType(t) && contains(switchTypes, getRegularTypeOfLiteralType(t))));
23236+
const defaultType = filterType(type, t => !(isUnitLikeType(t) && contains(switchTypes, getRegularTypeOfLiteralType(extractUnitType(t)))));
2322123237
return caseType.flags & TypeFlags.Never ? defaultType : getUnionType([caseType, defaultType]);
2322223238
}
2322323239

src/compiler/tracing.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,4 +331,5 @@ namespace ts { // eslint-disable-line one-namespace-per-file
331331

332332
// define after tracingEnabled is initialized
333333
export const startTracing = tracingEnabled.startTracing;
334+
export const dumpTracingLegend = tracingEnabled.dumpLegend;
334335
}

src/executeCommandLine/executeCommandLine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ namespace ts {
501501
updateSolutionBuilderHost(sys, cb, buildHost);
502502
const builder = createSolutionBuilder(buildHost, projects, buildOptions);
503503
const exitStatus = buildOptions.clean ? builder.clean() : builder.build();
504-
tracing?.dumpLegend();
504+
dumpTracingLegend(); // Will no-op if there hasn't been any tracing
505505
return sys.exit(exitStatus);
506506
}
507507

src/services/services.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,6 +1629,9 @@ namespace ts {
16291629
if (isNewExpression(node.parent) && node.pos === node.parent.pos) {
16301630
return node.parent.expression;
16311631
}
1632+
if (isNamedTupleMember(node.parent) && node.pos === node.parent.pos) {
1633+
return node.parent;
1634+
}
16321635
return node;
16331636
}
16341637

@@ -1643,6 +1646,7 @@ namespace ts {
16431646
case SyntaxKind.ThisKeyword:
16441647
case SyntaxKind.ThisType:
16451648
case SyntaxKind.SuperKeyword:
1649+
case SyntaxKind.NamedTupleMember:
16461650
return true;
16471651
default:
16481652
return false;

0 commit comments

Comments
 (0)