@@ -6420,11 +6420,11 @@ namespace ts {
6420
6420
* @param typeParameters The requested type parameters.
6421
6421
* @param minTypeArgumentCount The minimum number of required type arguments.
6422
6422
*/
6423
- function fillMissingTypeArguments(typeArguments: Type[] | undefined, typeParameters: TypeParameter[] | undefined, minTypeArgumentCount: number, isJavaScript : boolean) {
6423
+ function fillMissingTypeArguments(typeArguments: Type[] | undefined, typeParameters: TypeParameter[] | undefined, minTypeArgumentCount: number, isJavaScriptImplicitAny : boolean) {
6424
6424
const numTypeParameters = length(typeParameters);
6425
6425
if (numTypeParameters) {
6426
6426
const numTypeArguments = length(typeArguments);
6427
- if ((isJavaScript || numTypeArguments >= minTypeArgumentCount) && numTypeArguments <= numTypeParameters) {
6427
+ if ((isJavaScriptImplicitAny || numTypeArguments >= minTypeArgumentCount) && numTypeArguments <= numTypeParameters) {
6428
6428
if (!typeArguments) {
6429
6429
typeArguments = [];
6430
6430
}
@@ -6433,12 +6433,12 @@ namespace ts {
6433
6433
// If a type parameter does not have a default type, or if the default type
6434
6434
// is a forward reference, the empty object type is used.
6435
6435
for (let i = numTypeArguments; i < numTypeParameters; i++) {
6436
- typeArguments[i] = getDefaultTypeArgumentType(isJavaScript );
6436
+ typeArguments[i] = getDefaultTypeArgumentType(isJavaScriptImplicitAny );
6437
6437
}
6438
6438
for (let i = numTypeArguments; i < numTypeParameters; i++) {
6439
6439
const mapper = createTypeMapper(typeParameters, typeArguments);
6440
6440
const defaultType = getDefaultFromTypeParameter(typeParameters[i]);
6441
- typeArguments[i] = defaultType ? instantiateType(defaultType, mapper) : getDefaultTypeArgumentType(isJavaScript );
6441
+ typeArguments[i] = defaultType ? instantiateType(defaultType, mapper) : getDefaultTypeArgumentType(isJavaScriptImplicitAny );
6442
6442
}
6443
6443
}
6444
6444
}
@@ -6874,21 +6874,25 @@ namespace ts {
6874
6874
if (typeParameters) {
6875
6875
const numTypeArguments = length(node.typeArguments);
6876
6876
const minTypeArgumentCount = getMinTypeArgumentCount(typeParameters);
6877
- const isJavascript = isInJavaScriptFile(node);
6878
- if (!isJavascript && (numTypeArguments < minTypeArgumentCount || numTypeArguments > typeParameters.length)) {
6879
- error(node,
6880
- minTypeArgumentCount === typeParameters.length
6881
- ? Diagnostics.Generic_type_0_requires_1_type_argument_s
6882
- : Diagnostics.Generic_type_0_requires_between_1_and_2_type_arguments,
6883
- typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.WriteArrayAsGenericType),
6884
- minTypeArgumentCount,
6885
- typeParameters.length);
6877
+ const isJs = isInJavaScriptFile(node);
6878
+ const isJsImplicitAny = !compilerOptions.noImplicitAny && isJs;
6879
+ if (!isJsImplicitAny && (numTypeArguments < minTypeArgumentCount || numTypeArguments > typeParameters.length)) {
6880
+ const missingAugmentsTag = isJs && node.parent.kind !== SyntaxKind.JSDocAugmentsTag;
6881
+ const diag = minTypeArgumentCount === typeParameters.length
6882
+ ? missingAugmentsTag
6883
+ ? Diagnostics.Expected_0_type_arguments_provide_these_with_an_extends_tag
6884
+ : Diagnostics.Generic_type_0_requires_1_type_argument_s
6885
+ : missingAugmentsTag
6886
+ ? Diagnostics.Expected_0_1_type_arguments_provide_these_with_an_extends_tag
6887
+ : Diagnostics.Generic_type_0_requires_between_1_and_2_type_arguments;
6888
+ const typeStr = typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.WriteArrayAsGenericType);
6889
+ error(node, diag, typeStr, minTypeArgumentCount, typeParameters.length);
6886
6890
return unknownType;
6887
6891
}
6888
6892
// In a type reference, the outer type parameters of the referenced class or interface are automatically
6889
6893
// supplied as type arguments and the type reference only specifies arguments for the local type parameters
6890
6894
// of the class or interface.
6891
- const typeArguments = concatenate(type.outerTypeParameters, fillMissingTypeArguments(typeArgs, typeParameters, minTypeArgumentCount, isJavascript ));
6895
+ const typeArguments = concatenate(type.outerTypeParameters, fillMissingTypeArguments(typeArgs, typeParameters, minTypeArgumentCount, isJsImplicitAny ));
6892
6896
return createTypeReference(<GenericType>type, typeArguments);
6893
6897
}
6894
6898
if (node.typeArguments) {
0 commit comments