@@ -248,6 +248,12 @@ namespace ts {
248
248
ExportNamespace = 1 << 2,
249
249
}
250
250
251
+ const enum MinArgumentCountFlags {
252
+ None = 0,
253
+ StrongArityForUntypedJS = 1 << 0,
254
+ VoidIsNonOptional = 1 << 1,
255
+ }
256
+
251
257
function SymbolLinks(this: SymbolLinks) {
252
258
}
253
259
@@ -2410,7 +2416,7 @@ namespace ts {
2410
2416
2411
2417
function getTargetOfImportEqualsDeclaration(node: ImportEqualsDeclaration | VariableDeclaration, dontResolveAlias: boolean): Symbol | undefined {
2412
2418
if (isVariableDeclaration(node) && node.initializer && isPropertyAccessExpression(node.initializer)) {
2413
- const name = (getLeftmostPropertyAccessExpression (node.initializer.expression) as CallExpression).arguments[0] as StringLiteral;
2419
+ const name = (getLeftmostAccessExpression (node.initializer.expression) as CallExpression).arguments[0] as StringLiteral;
2414
2420
return isIdentifier(node.initializer.name)
2415
2421
? resolveSymbol(getPropertyOfType(resolveExternalModuleTypeByLiteral(name), node.initializer.name.escapedText))
2416
2422
: undefined;
@@ -2672,7 +2678,7 @@ namespace ts {
2672
2678
const suggestion = getSuggestedSymbolForNonexistentModule(name, targetSymbol);
2673
2679
if (suggestion !== undefined) {
2674
2680
const suggestionName = symbolToString(suggestion);
2675
- const diagnostic = error(name, Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_2 , moduleName, declarationName, suggestionName);
2681
+ const diagnostic = error(name, Diagnostics._0_has_no_exported_member_named_1_Did_you_mean_2 , moduleName, declarationName, suggestionName);
2676
2682
if (suggestion.valueDeclaration) {
2677
2683
addRelatedInfo(diagnostic,
2678
2684
createDiagnosticForNode(suggestion.valueDeclaration, Diagnostics._0_is_declared_here, suggestionName)
@@ -3051,7 +3057,12 @@ namespace ts {
3051
3057
symbol = getMergedSymbol(getSymbol(getExportsOfSymbol(namespace), right.escapedText, meaning));
3052
3058
if (!symbol) {
3053
3059
if (!ignoreErrors) {
3054
- error(right, Diagnostics.Namespace_0_has_no_exported_member_1, getFullyQualifiedName(namespace), declarationNameToString(right));
3060
+ const namespaceName = getFullyQualifiedName(namespace);
3061
+ const declarationName = declarationNameToString(right);
3062
+ const suggestion = getSuggestedSymbolForNonexistentModule(right, namespace);
3063
+ suggestion ?
3064
+ error(right, Diagnostics._0_has_no_exported_member_named_1_Did_you_mean_2, namespaceName, declarationName, symbolToString(suggestion)) :
3065
+ error(right, Diagnostics.Namespace_0_has_no_exported_member_1, namespaceName, declarationName);
3055
3066
}
3056
3067
return undefined;
3057
3068
}
@@ -9703,7 +9714,7 @@ namespace ts {
9703
9714
9704
9715
// fill in any as-yet-unresolved late-bound members.
9705
9716
const lateSymbols = createSymbolTable() as UnderscoreEscapedMap<TransientSymbol>;
9706
- for (const decl of symbol.declarations) {
9717
+ for (const decl of symbol.declarations || emptyArray ) {
9707
9718
const members = getMembersOfDeclaration(decl);
9708
9719
if (members) {
9709
9720
for (const member of members) {
@@ -9859,6 +9870,7 @@ namespace ts {
9859
9870
sig.resolvedReturnType = resolvedReturnType;
9860
9871
sig.resolvedTypePredicate = resolvedTypePredicate;
9861
9872
sig.minArgumentCount = minArgumentCount;
9873
+ sig.resolvedMinArgumentCount = undefined;
9862
9874
sig.target = undefined;
9863
9875
sig.mapper = undefined;
9864
9876
sig.unionSignatures = undefined;
@@ -11318,7 +11330,10 @@ namespace ts {
11318
11330
const signature = getSignatureFromDeclaration(node.parent);
11319
11331
const parameterIndex = node.parent.parameters.indexOf(node);
11320
11332
Debug.assert(parameterIndex >= 0);
11321
- return parameterIndex >= getMinArgumentCount(signature, /*strongArityForUntypedJS*/ true);
11333
+ // Only consider syntactic or instantiated parameters as optional, not `void` parameters as this function is used
11334
+ // in grammar checks and checking for `void` too early results in parameter types widening too early
11335
+ // and causes some noImplicitAny errors to be lost.
11336
+ return parameterIndex >= getMinArgumentCount(signature, MinArgumentCountFlags.StrongArityForUntypedJS | MinArgumentCountFlags.VoidIsNonOptional);
11322
11337
}
11323
11338
const iife = getImmediatelyInvokedFunctionExpression(node.parent);
11324
11339
if (iife) {
@@ -23023,12 +23038,16 @@ namespace ts {
23023
23038
const name = declaration.propertyName || declaration.name;
23024
23039
const parentType = getContextualTypeForVariableLikeDeclaration(parent) ||
23025
23040
parent.kind !== SyntaxKind.BindingElement && parent.initializer && checkDeclarationInitializer(parent);
23026
- if (parentType && !isBindingPattern(name) && !isComputedNonLiteralName(name)) {
23027
- const nameType = getLiteralTypeFromPropertyName(name);
23028
- if (isTypeUsableAsPropertyName(nameType)) {
23029
- const text = getPropertyNameFromType(nameType);
23030
- return getTypeOfPropertyOfType(parentType, text);
23031
- }
23041
+ if (!parentType || isBindingPattern(name) || isComputedNonLiteralName(name)) return undefined;
23042
+ if (parent.name.kind === SyntaxKind.ArrayBindingPattern) {
23043
+ const index = indexOfNode(declaration.parent.elements, declaration);
23044
+ if (index < 0) return undefined;
23045
+ return getContextualTypeForElementExpression(parentType, index);
23046
+ }
23047
+ const nameType = getLiteralTypeFromPropertyName(name);
23048
+ if (isTypeUsableAsPropertyName(nameType)) {
23049
+ const text = getPropertyNameFromType(nameType);
23050
+ return getTypeOfPropertyOfType(parentType, text);
23032
23051
}
23033
23052
}
23034
23053
@@ -28024,21 +28043,40 @@ namespace ts {
28024
28043
return length;
28025
28044
}
28026
28045
28027
- function getMinArgumentCount(signature: Signature, strongArityForUntypedJS?: boolean) {
28028
- if (signatureHasRestParameter(signature)) {
28029
- const restType = getTypeOfSymbol(signature.parameters[signature.parameters.length - 1]);
28030
- if (isTupleType(restType)) {
28031
- const firstOptionalIndex = findIndex(restType.target.elementFlags, f => !(f & ElementFlags.Required));
28032
- const requiredCount = firstOptionalIndex < 0 ? restType.target.fixedLength : firstOptionalIndex;
28033
- if (requiredCount > 0) {
28034
- return signature.parameters.length - 1 + requiredCount;
28046
+ function getMinArgumentCount(signature: Signature, flags?: MinArgumentCountFlags) {
28047
+ const strongArityForUntypedJS = flags! & MinArgumentCountFlags.StrongArityForUntypedJS;
28048
+ const voidIsNonOptional = flags! & MinArgumentCountFlags.VoidIsNonOptional;
28049
+ if (voidIsNonOptional || signature.resolvedMinArgumentCount === undefined) {
28050
+ let minArgumentCount: number | undefined;
28051
+ if (signatureHasRestParameter(signature)) {
28052
+ const restType = getTypeOfSymbol(signature.parameters[signature.parameters.length - 1]);
28053
+ if (isTupleType(restType)) {
28054
+ const firstOptionalIndex = findIndex(restType.target.elementFlags, f => !(f & ElementFlags.Required));
28055
+ const requiredCount = firstOptionalIndex < 0 ? restType.target.fixedLength : firstOptionalIndex;
28056
+ if (requiredCount > 0) {
28057
+ minArgumentCount = signature.parameters.length - 1 + requiredCount;
28058
+ }
28035
28059
}
28036
28060
}
28061
+ if (minArgumentCount === undefined) {
28062
+ if (!strongArityForUntypedJS && signature.flags & SignatureFlags.IsUntypedSignatureInJSFile) {
28063
+ return 0;
28064
+ }
28065
+ minArgumentCount = signature.minArgumentCount;
28066
+ }
28067
+ if (voidIsNonOptional) {
28068
+ return minArgumentCount;
28069
+ }
28070
+ for (let i = minArgumentCount - 1; i >= 0; i--) {
28071
+ const type = getTypeAtPosition(signature, i);
28072
+ if (filterType(type, acceptsVoid).flags & TypeFlags.Never) {
28073
+ break;
28074
+ }
28075
+ minArgumentCount = i;
28076
+ }
28077
+ signature.resolvedMinArgumentCount = minArgumentCount;
28037
28078
}
28038
- if (!strongArityForUntypedJS && signature.flags & SignatureFlags.IsUntypedSignatureInJSFile) {
28039
- return 0;
28040
- }
28041
- return signature.minArgumentCount;
28079
+ return signature.resolvedMinArgumentCount;
28042
28080
}
28043
28081
28044
28082
function hasEffectiveRestParameter(signature: Signature) {
0 commit comments