@@ -2496,7 +2496,7 @@ namespace ts {
2496
2496
&& isAliasableOrJsExpression(node.parent.right)
2497
2497
|| node.kind === SyntaxKind.ShorthandPropertyAssignment
2498
2498
|| node.kind === SyntaxKind.PropertyAssignment && isAliasableOrJsExpression((node as PropertyAssignment).initializer)
2499
- || isRequireVariableDeclaration(node, /*requireStringLiteralLikeArgument*/ true );
2499
+ || isRequireVariableDeclaration(node);
2500
2500
}
2501
2501
2502
2502
function isAliasableOrJsExpression(e: Expression) {
@@ -9186,7 +9186,6 @@ namespace ts {
9186
9186
return undefined;
9187
9187
}
9188
9188
switch (node.kind) {
9189
- case SyntaxKind.VariableStatement:
9190
9189
case SyntaxKind.ClassDeclaration:
9191
9190
case SyntaxKind.ClassExpression:
9192
9191
case SyntaxKind.InterfaceDeclaration:
@@ -9206,28 +9205,32 @@ namespace ts {
9206
9205
case SyntaxKind.JSDocEnumTag:
9207
9206
case SyntaxKind.JSDocCallbackTag:
9208
9207
case SyntaxKind.MappedType:
9209
- case SyntaxKind.ConditionalType:
9208
+ case SyntaxKind.ConditionalType: {
9210
9209
const outerTypeParameters = getOuterTypeParameters(node, includeThisTypes);
9211
9210
if (node.kind === SyntaxKind.MappedType) {
9212
9211
return append(outerTypeParameters, getDeclaredTypeOfTypeParameter(getSymbolOfNode((<MappedTypeNode>node).typeParameter)));
9213
9212
}
9214
9213
else if (node.kind === SyntaxKind.ConditionalType) {
9215
9214
return concatenate(outerTypeParameters, getInferTypeParameters(<ConditionalTypeNode>node));
9216
9215
}
9217
- else if (node.kind === SyntaxKind.VariableStatement && !isInJSFile(node)) {
9218
- break;
9219
- }
9220
9216
const outerAndOwnTypeParameters = appendTypeParameters(outerTypeParameters, getEffectiveTypeParameterDeclarations(<DeclarationWithTypeParameters>node));
9221
9217
const thisType = includeThisTypes &&
9222
9218
(node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.ClassExpression || node.kind === SyntaxKind.InterfaceDeclaration || isJSConstructor(node)) &&
9223
9219
getDeclaredTypeOfClassOrInterface(getSymbolOfNode(node as ClassLikeDeclaration | InterfaceDeclaration)).thisType;
9224
9220
return thisType ? append(outerAndOwnTypeParameters, thisType) : outerAndOwnTypeParameters;
9221
+ }
9225
9222
case SyntaxKind.JSDocParameterTag:
9226
9223
const paramSymbol = getParameterSymbolFromJSDoc(node as JSDocParameterTag);
9227
9224
if (paramSymbol) {
9228
9225
node = paramSymbol.valueDeclaration;
9229
9226
}
9230
9227
break;
9228
+ case SyntaxKind.JSDocComment: {
9229
+ const outerTypeParameters = getOuterTypeParameters(node, includeThisTypes);
9230
+ return (node as JSDoc).tags
9231
+ ? appendTypeParameters(outerTypeParameters, flatMap((node as JSDoc).tags, t => isJSDocTemplateTag(t) ? t.typeParameters : undefined))
9232
+ : outerTypeParameters;
9233
+ }
9231
9234
}
9232
9235
}
9233
9236
}
@@ -13381,7 +13384,7 @@ namespace ts {
13381
13384
return types;
13382
13385
}
13383
13386
13384
- function removeRedundantLiteralTypes(types: Type[], includes: TypeFlags) {
13387
+ function removeRedundantLiteralTypes(types: Type[], includes: TypeFlags, reduceVoidUndefined: boolean ) {
13385
13388
let i = types.length;
13386
13389
while (i > 0) {
13387
13390
i--;
@@ -13392,7 +13395,7 @@ namespace ts {
13392
13395
flags & TypeFlags.NumberLiteral && includes & TypeFlags.Number ||
13393
13396
flags & TypeFlags.BigIntLiteral && includes & TypeFlags.BigInt ||
13394
13397
flags & TypeFlags.UniqueESSymbol && includes & TypeFlags.ESSymbol ||
13395
- flags & TypeFlags.Undefined && includes & TypeFlags.Void ||
13398
+ reduceVoidUndefined && flags & TypeFlags.Undefined && includes & TypeFlags.Void ||
13396
13399
isFreshLiteralType(t) && containsType(types, (<LiteralType>t).regularType);
13397
13400
if (remove) {
13398
13401
orderedRemoveItemAt(types, i);
@@ -13459,7 +13462,7 @@ namespace ts {
13459
13462
return includes & TypeFlags.Any ? includes & TypeFlags.IncludesWildcard ? wildcardType : anyType : unknownType;
13460
13463
}
13461
13464
if (includes & (TypeFlags.Literal | TypeFlags.UniqueESSymbol) || includes & TypeFlags.Void && includes & TypeFlags.Undefined) {
13462
- removeRedundantLiteralTypes(typeSet, includes);
13465
+ removeRedundantLiteralTypes(typeSet, includes, !!(unionReduction & UnionReduction.Subtype) );
13463
13466
}
13464
13467
if (includes & TypeFlags.StringLiteral && includes & TypeFlags.TemplateLiteral) {
13465
13468
removeStringLiteralsMatchedByTemplateLiterals(typeSet);
@@ -22079,7 +22082,16 @@ namespace ts {
22079
22082
const type = getTypeOfDottedName((<PropertyAccessExpression>node).expression, diagnostic);
22080
22083
if (type) {
22081
22084
const name = (<PropertyAccessExpression>node).name;
22082
- const prop = getPropertyOfType(type, isPrivateIdentifier(name) ? getSymbolNameForPrivateIdentifier(type.symbol, name.escapedText) : name.escapedText);
22085
+ let prop: Symbol | undefined;
22086
+ if (isPrivateIdentifier(name)) {
22087
+ if (!type.symbol) {
22088
+ return undefined;
22089
+ }
22090
+ prop = getPropertyOfType(type, getSymbolNameForPrivateIdentifier(type.symbol, name.escapedText));
22091
+ }
22092
+ else {
22093
+ prop = getPropertyOfType(type, name.escapedText);
22094
+ }
22083
22095
return prop && getExplicitTypeOfSymbol(prop, diagnostic);
22084
22096
}
22085
22097
return undefined;
@@ -34565,7 +34577,7 @@ namespace ts {
34565
34577
}
34566
34578
// For a commonjs `const x = require`, validate the alias and exit
34567
34579
const symbol = getSymbolOfNode(node);
34568
- if (symbol.flags & SymbolFlags.Alias && isRequireVariableDeclaration(node, /*requireStringLiteralLikeArgument*/ true )) {
34580
+ if (symbol.flags & SymbolFlags.Alias && isRequireVariableDeclaration(node)) {
34569
34581
checkAliasSymbol(node);
34570
34582
return;
34571
34583
}
@@ -35070,18 +35082,8 @@ namespace ts {
35070
35082
// want to say that number is not an array type. But if the input was just
35071
35083
// number and string input is allowed, we want to say that number is not an
35072
35084
// array type or a string type.
35073
- const yieldType = getIterationTypeOfIterable(use, IterationTypeKind.Yield, inputType, /*errorNode*/ undefined);
35074
- const [defaultDiagnostic, maybeMissingAwait]: [DiagnosticMessage, boolean] = !(use & IterationUse.AllowsStringInputFlag) || hasStringConstituent
35075
- ? downlevelIteration
35076
- ? [Diagnostics.Type_0_is_not_an_array_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator, true]
35077
- : yieldType
35078
- ? [Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators, false]
35079
- : [Diagnostics.Type_0_is_not_an_array_type, true]
35080
- : downlevelIteration
35081
- ? [Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator, true]
35082
- : yieldType
35083
- ? [Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators, false]
35084
- : [Diagnostics.Type_0_is_not_an_array_type_or_a_string_type, true];
35085
+ const allowsStrings = !!(use & IterationUse.AllowsStringInputFlag) && !hasStringConstituent;
35086
+ const [defaultDiagnostic, maybeMissingAwait] = getIterationDiagnosticDetails(allowsStrings, downlevelIteration);
35085
35087
errorAndMaybeSuggestAwait(
35086
35088
errorNode,
35087
35089
maybeMissingAwait && !!getAwaitedTypeOfPromise(arrayType),
@@ -35102,6 +35104,45 @@ namespace ts {
35102
35104
}
35103
35105
35104
35106
return (use & IterationUse.PossiblyOutOfBounds) ? includeUndefinedInIndexSignature(arrayElementType) : arrayElementType;
35107
+
35108
+ function getIterationDiagnosticDetails(allowsStrings: boolean, downlevelIteration: boolean | undefined): [DiagnosticMessage, boolean] {
35109
+ if (downlevelIteration) {
35110
+ return allowsStrings
35111
+ ? [Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator, true]
35112
+ : [Diagnostics.Type_0_is_not_an_array_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator, true];
35113
+ }
35114
+
35115
+ const yieldType = getIterationTypeOfIterable(use, IterationTypeKind.Yield, inputType, /*errorNode*/ undefined);
35116
+
35117
+ if (yieldType) {
35118
+ return [Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators, false];
35119
+ }
35120
+
35121
+ if (isES2015OrLaterIterable(inputType.symbol?.escapedName)) {
35122
+ return [Diagnostics.Type_0_can_only_be_iterated_through_when_using_the_downlevelIteration_flag_or_with_a_target_of_es2015_or_higher, true];
35123
+ }
35124
+
35125
+ return allowsStrings
35126
+ ? [Diagnostics.Type_0_is_not_an_array_type_or_a_string_type, true]
35127
+ : [Diagnostics.Type_0_is_not_an_array_type, true];
35128
+ }
35129
+ }
35130
+
35131
+ function isES2015OrLaterIterable(n: __String) {
35132
+ switch (n) {
35133
+ case "Float32Array":
35134
+ case "Float64Array":
35135
+ case "Int16Array":
35136
+ case "Int32Array":
35137
+ case "Int8Array":
35138
+ case "NodeList":
35139
+ case "Uint16Array":
35140
+ case "Uint32Array":
35141
+ case "Uint8Array":
35142
+ case "Uint8ClampedArray":
35143
+ return true;
35144
+ }
35145
+ return false;
35105
35146
}
35106
35147
35107
35148
/**
@@ -40906,7 +40947,7 @@ namespace ts {
40906
40947
if (isStringLiteral(node.name) && node.name.text === "constructor") {
40907
40948
return grammarErrorOnNode(node.name, Diagnostics.Classes_may_not_have_a_field_named_constructor);
40908
40949
}
40909
- if (checkGrammarForInvalidDynamicName(node.name, Diagnostics.A_computed_property_name_in_a_class_property_declaration_must_refer_to_an_expression_whose_type_is_a_literal_type_or_a_unique_symbol_type )) {
40950
+ if (checkGrammarForInvalidDynamicName(node.name, Diagnostics.A_computed_property_name_in_a_class_property_declaration_must_have_a_simple_literal_type_or_a_unique_symbol_type )) {
40910
40951
return true;
40911
40952
}
40912
40953
if (languageVersion < ScriptTarget.ES2015 && isPrivateIdentifier(node.name)) {
0 commit comments