Skip to content

Commit d3f2a17

Browse files
Merge remote-tracking branch 'origin/main' into release-5.4
2 parents a450bda + 36f9e9e commit d3f2a17

File tree

28 files changed

+5801
-1599
lines changed

28 files changed

+5801
-1599
lines changed

package-lock.json

+18-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/compiler/checker.ts

+14-7
Original file line numberDiff line numberDiff line change
@@ -17119,19 +17119,25 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1711917119
}
1712017120

1712117121
function removeStringLiteralsMatchedByTemplateLiterals(types: Type[]) {
17122-
const templates = filter(types, t => !!(t.flags & TypeFlags.TemplateLiteral) && isPatternLiteralType(t)) as TemplateLiteralType[];
17122+
const templates = filter(types, isPatternLiteralType) as (TemplateLiteralType | StringMappingType)[];
1712317123
if (templates.length) {
1712417124
let i = types.length;
1712517125
while (i > 0) {
1712617126
i--;
1712717127
const t = types[i];
17128-
if (t.flags & TypeFlags.StringLiteral && some(templates, template => isTypeMatchedByTemplateLiteralType(t, template))) {
17128+
if (t.flags & TypeFlags.StringLiteral && some(templates, template => isTypeMatchedByTemplateLiteralOrStringMapping(t, template))) {
1712917129
orderedRemoveItemAt(types, i);
1713017130
}
1713117131
}
1713217132
}
1713317133
}
1713417134

17135+
function isTypeMatchedByTemplateLiteralOrStringMapping(type: Type, template: TemplateLiteralType | StringMappingType) {
17136+
return template.flags & TypeFlags.TemplateLiteral ?
17137+
isTypeMatchedByTemplateLiteralType(type, template as TemplateLiteralType) :
17138+
isMemberOfStringMapping(type, template);
17139+
}
17140+
1713517141
function removeConstrainedTypeVariables(types: Type[]) {
1713617142
const typeVariables: TypeVariable[] = [];
1713717143
// First collect a list of the type variables occurring in constraining intersections.
@@ -17246,7 +17252,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1724617252
if (includes & (TypeFlags.Enum | TypeFlags.Literal | TypeFlags.UniqueESSymbol | TypeFlags.TemplateLiteral | TypeFlags.StringMapping) || includes & TypeFlags.Void && includes & TypeFlags.Undefined) {
1724717253
removeRedundantLiteralTypes(typeSet, includes, !!(unionReduction & UnionReduction.Subtype));
1724817254
}
17249-
if (includes & TypeFlags.StringLiteral && includes & TypeFlags.TemplateLiteral) {
17255+
if (includes & TypeFlags.StringLiteral && includes & (TypeFlags.TemplateLiteral | TypeFlags.StringMapping)) {
1725017256
removeStringLiteralsMatchedByTemplateLiterals(typeSet);
1725117257
}
1725217258
if (includes & TypeFlags.IncludesConstrainedTypeVariable) {
@@ -17442,18 +17448,19 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1744217448
}
1744317449

1744417450
/**
17445-
* Returns `true` if the intersection of the template literals and string literals is the empty set, eg `get${string}` & "setX", and should reduce to `never`
17451+
* Returns true if the intersection of the template literals and string literals is the empty set,
17452+
* for example `get${string}` & "setX", and should reduce to never.
1744617453
*/
1744717454
function extractRedundantTemplateLiterals(types: Type[]): boolean {
1744817455
let i = types.length;
1744917456
const literals = filter(types, t => !!(t.flags & TypeFlags.StringLiteral));
1745017457
while (i > 0) {
1745117458
i--;
1745217459
const t = types[i];
17453-
if (!(t.flags & TypeFlags.TemplateLiteral)) continue;
17460+
if (!(t.flags & (TypeFlags.TemplateLiteral | TypeFlags.StringMapping))) continue;
1745417461
for (const t2 of literals) {
1745517462
if (isTypeSubtypeOf(t2, t)) {
17456-
// eg, ``get${T}` & "getX"` is just `"getX"`
17463+
// For example, `get${T}` & "getX" is just "getX", and Lowercase<string> & "foo" is just "foo"
1745717464
orderedRemoveItemAt(types, i);
1745817465
break;
1745917466
}
@@ -17563,7 +17570,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1756317570
) {
1756417571
return neverType;
1756517572
}
17566-
if (includes & TypeFlags.TemplateLiteral && includes & TypeFlags.StringLiteral && extractRedundantTemplateLiterals(typeSet)) {
17573+
if (includes & (TypeFlags.TemplateLiteral | TypeFlags.StringMapping) && includes & TypeFlags.StringLiteral && extractRedundantTemplateLiterals(typeSet)) {
1756717574
return neverType;
1756817575
}
1756917576
if (includes & TypeFlags.Any) {

src/compiler/types.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -6125,6 +6125,8 @@ export const enum TypeFlags {
61256125
NonPrimitive = 1 << 26, // intrinsic object type
61266126
TemplateLiteral = 1 << 27, // Template literal type
61276127
StringMapping = 1 << 28, // Uppercase/Lowercase type
6128+
/** @internal */
6129+
Reserved1 = 1 << 29, // Used by union/intersection type construction
61286130

61296131
/** @internal */
61306132
AnyOrUnknown = Any | Unknown,
@@ -6172,7 +6174,7 @@ export const enum TypeFlags {
61726174
Narrowable = Any | Unknown | StructuredOrInstantiable | StringLike | NumberLike | BigIntLike | BooleanLike | ESSymbol | UniqueESSymbol | NonPrimitive,
61736175
// The following flags are aggregated during union and intersection type construction
61746176
/** @internal */
6175-
IncludesMask = Any | Unknown | Primitive | Never | Object | Union | Intersection | NonPrimitive | TemplateLiteral,
6177+
IncludesMask = Any | Unknown | Primitive | Never | Object | Union | Intersection | NonPrimitive | TemplateLiteral | StringMapping,
61766178
// The following flags are used for different purposes during union and intersection type construction
61776179
/** @internal */
61786180
IncludesMissingType = TypeParameter,
@@ -6185,7 +6187,7 @@ export const enum TypeFlags {
61856187
/** @internal */
61866188
IncludesInstantiable = Substitution,
61876189
/** @internal */
6188-
IncludesConstrainedTypeVariable = StringMapping,
6190+
IncludesConstrainedTypeVariable = Reserved1,
61896191
/** @internal */
61906192
NotPrimitiveUnion = Any | Unknown | Void | Never | Object | Intersection | IncludesInstantiable,
61916193
}

src/server/protocol.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ export interface Request extends Message {
211211
/**
212212
* Request to reload the project structure for all the opened files
213213
*/
214-
export interface ReloadProjectsRequest extends Message {
214+
export interface ReloadProjectsRequest extends Request {
215215
command: CommandTypes.ReloadProjects;
216216
}
217217

0 commit comments

Comments
 (0)