Skip to content

Commit 05c993b

Browse files
committed
Merge branch 'main' into gabritto/issue45045
2 parents 85e1f26 + 5e496d5 commit 05c993b

File tree

83 files changed

+2232
-638
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+2232
-638
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "typescript",
33
"author": "Microsoft Corp.",
44
"homepage": "https://www.typescriptlang.org/",
5-
"version": "4.4.0",
5+
"version": "4.5.0",
66
"license": "Apache-2.0",
77
"description": "TypeScript is a language for application scale JavaScript development",
88
"keywords": [

src/compiler/binder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2294,7 +2294,7 @@ namespace ts {
22942294
// Provide specialized messages to help the user understand why we think they're in
22952295
// strict mode.
22962296
if (getContainingClass(node)) {
2297-
return Diagnostics.Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode;
2297+
return Diagnostics.Code_contained_in_a_class_is_evaluated_in_JavaScript_s_strict_mode_which_does_not_allow_this_use_of_0_For_more_information_see_https_Colon_Slash_Slashdeveloper_mozilla_org_Slashen_US_Slashdocs_SlashWeb_SlashJavaScript_SlashReference_SlashStrict_mode;
22982298
}
22992299

23002300
if (file.externalModuleIndicator) {

src/compiler/checker.ts

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14929,40 +14929,35 @@ namespace ts {
1492914929
return !!(type.flags & TypeFlags.TemplateLiteral) && every((type as TemplateLiteralType).types, isPatternLiteralPlaceholderType);
1493014930
}
1493114931

14932+
function isGenericType(type: Type): boolean {
14933+
return !!getGenericObjectFlags(type);
14934+
}
14935+
1493214936
function isGenericObjectType(type: Type): boolean {
14933-
if (type.flags & TypeFlags.UnionOrIntersection) {
14934-
if (!((type as UnionOrIntersectionType).objectFlags & ObjectFlags.IsGenericObjectTypeComputed)) {
14935-
(type as UnionOrIntersectionType).objectFlags |= ObjectFlags.IsGenericObjectTypeComputed |
14936-
(some((type as UnionOrIntersectionType).types, isGenericObjectType) ? ObjectFlags.IsGenericObjectType : 0);
14937-
}
14938-
return !!((type as UnionOrIntersectionType).objectFlags & ObjectFlags.IsGenericObjectType);
14939-
}
14940-
if (type.flags & TypeFlags.Substitution) {
14941-
if (!((type as SubstitutionType).objectFlags & ObjectFlags.IsGenericObjectTypeComputed)) {
14942-
(type as SubstitutionType).objectFlags |= ObjectFlags.IsGenericObjectTypeComputed |
14943-
(isGenericObjectType((type as SubstitutionType).substitute) || isGenericObjectType((type as SubstitutionType).baseType) ? ObjectFlags.IsGenericObjectType : 0);
14944-
}
14945-
return !!((type as SubstitutionType).objectFlags & ObjectFlags.IsGenericObjectType);
14946-
}
14947-
return !!(type.flags & TypeFlags.InstantiableNonPrimitive) || isGenericMappedType(type) || isGenericTupleType(type);
14937+
return !!(getGenericObjectFlags(type) & ObjectFlags.IsGenericObjectType);
1494814938
}
1494914939

1495014940
function isGenericIndexType(type: Type): boolean {
14941+
return !!(getGenericObjectFlags(type) & ObjectFlags.IsGenericIndexType);
14942+
}
14943+
14944+
function getGenericObjectFlags(type: Type): ObjectFlags {
1495114945
if (type.flags & TypeFlags.UnionOrIntersection) {
14952-
if (!((type as UnionOrIntersectionType).objectFlags & ObjectFlags.IsGenericIndexTypeComputed)) {
14953-
(type as UnionOrIntersectionType).objectFlags |= ObjectFlags.IsGenericIndexTypeComputed |
14954-
(some((type as UnionOrIntersectionType).types, isGenericIndexType) ? ObjectFlags.IsGenericIndexType : 0);
14946+
if (!((type as UnionOrIntersectionType).objectFlags & ObjectFlags.IsGenericTypeComputed)) {
14947+
(type as UnionOrIntersectionType).objectFlags |= ObjectFlags.IsGenericTypeComputed |
14948+
reduceLeft((type as UnionOrIntersectionType).types, (flags, t) => flags | getGenericObjectFlags(t), 0);
1495514949
}
14956-
return !!((type as UnionOrIntersectionType).objectFlags & ObjectFlags.IsGenericIndexType);
14950+
return (type as UnionOrIntersectionType).objectFlags & ObjectFlags.IsGenericType;
1495714951
}
1495814952
if (type.flags & TypeFlags.Substitution) {
14959-
if (!((type as SubstitutionType).objectFlags & ObjectFlags.IsGenericIndexTypeComputed)) {
14960-
(type as SubstitutionType).objectFlags |= ObjectFlags.IsGenericIndexTypeComputed |
14961-
(isGenericIndexType((type as SubstitutionType).substitute) || isGenericIndexType((type as SubstitutionType).baseType) ? ObjectFlags.IsGenericIndexType : 0);
14953+
if (!((type as SubstitutionType).objectFlags & ObjectFlags.IsGenericTypeComputed)) {
14954+
(type as SubstitutionType).objectFlags |= ObjectFlags.IsGenericTypeComputed |
14955+
getGenericObjectFlags((type as SubstitutionType).substitute) | getGenericObjectFlags((type as SubstitutionType).baseType);
1496214956
}
14963-
return !!((type as SubstitutionType).objectFlags & ObjectFlags.IsGenericIndexType);
14957+
return (type as SubstitutionType).objectFlags & ObjectFlags.IsGenericType;
1496414958
}
14965-
return !!(type.flags & (TypeFlags.InstantiableNonPrimitive | TypeFlags.Index | TypeFlags.TemplateLiteral | TypeFlags.StringMapping)) && !isPatternLiteralType(type);
14959+
return (type.flags & TypeFlags.InstantiableNonPrimitive || isGenericMappedType(type) || isGenericTupleType(type) ? ObjectFlags.IsGenericObjectType : 0) |
14960+
(type.flags & (TypeFlags.InstantiableNonPrimitive | TypeFlags.Index | TypeFlags.TemplateLiteral | TypeFlags.StringMapping) && !isPatternLiteralType(type) ? ObjectFlags.IsGenericIndexType : 0);
1496614961
}
1496714962

1496814963
function isThisTypeParameter(type: Type): boolean {
@@ -15239,7 +15234,7 @@ namespace ts {
1523915234
while (true) {
1524015235
const isUnwrapped = isTypicalNondistributiveConditional(root);
1524115236
const checkType = instantiateType(unwrapNondistributiveConditionalTuple(root, getActualTypeVariable(root.checkType)), mapper);
15242-
const checkTypeInstantiable = isGenericObjectType(checkType) || isGenericIndexType(checkType);
15237+
const checkTypeInstantiable = isGenericType(checkType);
1524315238
const extendsType = instantiateType(unwrapNondistributiveConditionalTuple(root, root.extendsType), mapper);
1524415239
if (checkType === wildcardType || extendsType === wildcardType) {
1524515240
return wildcardType;
@@ -15261,7 +15256,7 @@ namespace ts {
1526115256
// Instantiate the extends type including inferences for 'infer T' type parameters
1526215257
const inferredExtendsType = combinedMapper ? instantiateType(unwrapNondistributiveConditionalTuple(root, root.extendsType), combinedMapper) : extendsType;
1526315258
// We attempt to resolve the conditional type only when the check and extends types are non-generic
15264-
if (!checkTypeInstantiable && !isGenericObjectType(inferredExtendsType) && !isGenericIndexType(inferredExtendsType)) {
15259+
if (!checkTypeInstantiable && !isGenericType(inferredExtendsType)) {
1526515260
// Return falseType for a definitely false extends check. We check an instantiations of the two
1526615261
// types with type parameters mapped to the wildcard type, the most permissive instantiations
1526715262
// possible (the wildcard type is assignable to and from all types). If those are not related,
@@ -19489,8 +19484,8 @@ namespace ts {
1948919484
continue;
1949019485
}
1949119486
if (isApplicableIndexType(getLiteralTypeFromProperty(prop, TypeFlags.StringOrNumberLiteralOrUnique), keyType)) {
19492-
const propType = getTypeOfSymbol(prop);
19493-
const type = propType.flags & TypeFlags.Undefined || keyType === numberType || !(prop.flags & SymbolFlags.Optional)
19487+
const propType = getNonMissingTypeOfSymbol(prop);
19488+
const type = exactOptionalPropertyTypes || propType.flags & TypeFlags.Undefined || keyType === numberType || !(prop.flags & SymbolFlags.Optional)
1949419489
? propType
1949519490
: getTypeWithFacts(propType, TypeFacts.NEUndefined);
1949619491
const related = isRelatedTo(type, targetInfo.type, reportErrors);
@@ -24296,17 +24291,13 @@ namespace ts {
2429624291
return !!(type.flags & TypeFlags.Instantiable && !maybeTypeOfKind(getBaseConstraintOrType(type), TypeFlags.Nullable));
2429724292
}
2429824293

24299-
function containsGenericType(type: Type): boolean {
24300-
return !!(type.flags & TypeFlags.Instantiable || type.flags & TypeFlags.UnionOrIntersection && some((type as UnionOrIntersectionType).types, containsGenericType));
24301-
}
24302-
2430324294
function hasNonBindingPatternContextualTypeWithNoGenericTypes(node: Node) {
2430424295
// Computing the contextual type for a child of a JSX element involves resolving the type of the
2430524296
// element's tag name, so we exclude that here to avoid circularities.
2430624297
const contextualType = (isIdentifier(node) || isPropertyAccessExpression(node) || isElementAccessExpression(node)) &&
2430724298
!((isJsxOpeningElement(node.parent) || isJsxSelfClosingElement(node.parent)) && node.parent.tagName === node) &&
2430824299
getContextualType(node, ContextFlags.SkipBindingPatterns);
24309-
return contextualType && !someType(contextualType, containsGenericType);
24300+
return contextualType && !isGenericType(contextualType);
2431024301
}
2431124302

2431224303
function getNarrowableTypeForReference(type: Type, reference: Node, checkMode?: CheckMode) {
@@ -41717,7 +41708,7 @@ namespace ts {
4171741708
return grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_must_have_a_type_annotation);
4171841709
}
4171941710
const type = getTypeFromTypeNode(parameter.type);
41720-
if (someType(type, t => !!(t.flags & TypeFlags.StringOrNumberLiteralOrUnique)) || isGenericIndexType(type) || isGenericObjectType(type)) {
41711+
if (someType(type, t => !!(t.flags & TypeFlags.StringOrNumberLiteralOrUnique)) || isGenericType(type)) {
4172141712
return grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_type_cannot_be_a_literal_type_or_generic_type_Consider_using_a_mapped_object_type_instead);
4172241713
}
4172341714
if (!everyType(type, isValidIndexKeyType)) {

src/compiler/commandLineParser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ namespace ts {
223223
type: "boolean",
224224
showInSimplifiedHelpView: true,
225225
category: Diagnostics.Output_Formatting,
226-
description: Diagnostics.Enable_color_and_formatting_in_output_to_make_compiler_errors_easier_to_read,
226+
description: Diagnostics.Enable_color_and_formatting_in_TypeScript_s_output_to_make_compiler_errors_easier_to_read,
227227
defaultValueDescription: "true"
228228
},
229229
{
@@ -553,7 +553,7 @@ namespace ts {
553553
type: "boolean",
554554
showInSimplifiedHelpView: true,
555555
category: Diagnostics.Emit,
556-
description: Diagnostics.Disable_emitting_file_from_a_compilation,
556+
description: Diagnostics.Disable_emitting_files_from_a_compilation,
557557
transpileOptionValue: undefined,
558558
defaultValueDescription: "false"
559559
},

src/compiler/corePublic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace ts {
22
// WARNING: The script `configurePrerelease.ts` uses a regexp to parse out these values.
33
// If changing the text in this section, be sure to test `configurePrerelease` too.
4-
export const versionMajorMinor = "4.4";
4+
export const versionMajorMinor = "4.5";
55
// The following is baselined as a literal template type without intervention
66
/** The version of the TypeScript compiler release */
77
// eslint-disable-next-line @typescript-eslint/no-inferrable-types

src/compiler/diagnosticMessages.json

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@
663663
"category": "Error",
664664
"code": 1208
665665
},
666-
"Invalid use of '{0}'. Class definitions are automatically in strict mode.": {
666+
"Code contained in a class is evaluated in JavaScript's strict mode which does not allow this use of '{0}'. For more information, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode.": {
667667
"category": "Error",
668668
"code": 1210
669669
},
@@ -5459,7 +5459,7 @@
54595459
"category": "Message",
54605460
"code": 6659
54615461
},
5462-
"Disable emitting file from a compilation.": {
5462+
"Disable emitting files from a compilation.": {
54635463
"category": "Message",
54645464
"code": 6660
54655465
},
@@ -5559,7 +5559,7 @@
55595559
"category": "Message",
55605560
"code": 6684
55615561
},
5562-
"Enable color and formatting in output to make compiler errors easier to read": {
5562+
"Enable color and formatting in TypeScript's output to make compiler errors easier to read": {
55635563
"category": "Message",
55645564
"code": 6685
55655565
},
@@ -5788,7 +5788,7 @@
57885788
"category": "Message",
57895789
"code": 6923
57905790
},
5791-
"Ignoring tsconfig.json, compiles the specified files with default compiler options": {
5791+
"Ignoring tsconfig.json, compiles the specified files with default compiler options.": {
57925792
"category": "Message",
57935793
"code": 6924
57945794
},
@@ -5800,15 +5800,15 @@
58005800
"category": "Message",
58015801
"code": 6926
58025802
},
5803-
"Compiles the TypeScript project located at the specified path": {
5803+
"Compiles the TypeScript project located at the specified path.": {
58045804
"category": "Message",
58055805
"code": 6927
58065806
},
58075807
"An expanded version of this information, showing all possible compiler options": {
58085808
"category": "Message",
58095809
"code": 6928
58105810
},
5811-
"Compiles the current project, with additional settings": {
5811+
"Compiles the current project, with additional settings.": {
58125812
"category": "Message",
58135813
"code": 6929
58145814
},
@@ -7110,6 +7110,14 @@
71107110
"category": "Message",
71117111
"code": 95166
71127112
},
7113+
"Add missing attributes": {
7114+
"category": "Message",
7115+
"code": 95167
7116+
},
7117+
"Add all missing attributes": {
7118+
"category": "Message",
7119+
"code": 95168
7120+
},
71137121

71147122
"No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer.": {
71157123
"category": "Error",

src/compiler/types.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5267,23 +5267,23 @@ namespace ts {
52675267

52685268
// Flags that require TypeFlags.UnionOrIntersection or TypeFlags.Substitution
52695269
/* @internal */
5270-
IsGenericObjectTypeComputed = 1 << 22, // IsGenericObjectType flag has been computed
5270+
IsGenericTypeComputed = 1 << 22, // IsGenericObjectType flag has been computed
52715271
/* @internal */
52725272
IsGenericObjectType = 1 << 23, // Union or intersection contains generic object type
52735273
/* @internal */
5274-
IsGenericIndexTypeComputed = 1 << 24, // IsGenericIndexType flag has been computed
5274+
IsGenericIndexType = 1 << 24, // Union or intersection contains generic index type
52755275
/* @internal */
5276-
IsGenericIndexType = 1 << 25, // Union or intersection contains generic index type
5276+
IsGenericType = IsGenericObjectType | IsGenericIndexType,
52775277

52785278
// Flags that require TypeFlags.Union
52795279
/* @internal */
5280-
ContainsIntersections = 1 << 26, // Union contains intersections
5280+
ContainsIntersections = 1 << 25, // Union contains intersections
52815281

52825282
// Flags that require TypeFlags.Intersection
52835283
/* @internal */
5284-
IsNeverIntersectionComputed = 1 << 26, // IsNeverLike flag has been computed
5284+
IsNeverIntersectionComputed = 1 << 25, // IsNeverLike flag has been computed
52855285
/* @internal */
5286-
IsNeverIntersection = 1 << 27, // Intersection reduces to never
5286+
IsNeverIntersection = 1 << 26, // Intersection reduces to never
52875287
}
52885288

52895289
/* @internal */

0 commit comments

Comments
 (0)