Skip to content

Commit abd44b1

Browse files
Error on inferred '{}' type.
1 parent 07a893d commit abd44b1

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

Diff for: src/compiler/checker.ts

+20-5
Original file line numberDiff line numberDiff line change
@@ -6239,7 +6239,7 @@ module ts {
62396239
return getSignatureInstantiation(signature, getInferredTypes(context));
62406240
}
62416241

6242-
function inferTypeArguments(signature: Signature, args: Expression[], excludeArgument: boolean[]): InferenceContext {
6242+
function inferTypeArguments(signature: Signature, callNode: CallLikeExpression, args: Expression[], excludeArgument: boolean[]): InferenceContext {
62436243
var typeParameters = signature.typeParameters;
62446244
var context = createInferenceContext(typeParameters, /*inferUnionTypes*/ false);
62456245
var inferenceMapper = createInferenceMapper(context);
@@ -6281,9 +6281,9 @@ module ts {
62816281
// Inference has failed if the inferenceFailureType type is in list of inferences
62826282
context.failedTypeParameterIndex = indexOf(inferredTypes, inferenceFailureType);
62836283

6284-
// Wipe out the inferenceFailureType from the array so that error recovery can work properly
62856284
for (var i = 0; i < inferredTypes.length; i++) {
62866285
if (inferredTypes[i] === inferenceFailureType) {
6286+
// Wipe out the inferenceFailureType from the array so that error recovery can work properly
62876287
inferredTypes[i] = unknownType;
62886288
}
62896289
}
@@ -6529,33 +6529,48 @@ module ts {
65296529

65306530
var originalCandidate = candidates[i];
65316531
var inferenceResult: InferenceContext;
6532+
var typeArgumentTypes: Type[];
65326533

65336534
while (true) {
65346535
var candidate = originalCandidate;
65356536
if (candidate.typeParameters) {
6536-
var typeArgumentTypes: Type[];
65376537
var typeArgumentsAreValid: boolean;
65386538
if (typeArguments) {
65396539
typeArgumentTypes = new Array<Type>(candidate.typeParameters.length);
65406540
typeArgumentsAreValid = checkTypeArguments(candidate, typeArguments, typeArgumentTypes, /*reportErrors*/ false)
65416541
}
65426542
else {
6543-
inferenceResult = inferTypeArguments(candidate, args, excludeArgument);
6544-
typeArgumentsAreValid = inferenceResult.failedTypeParameterIndex < 0;
6543+
inferenceResult = inferTypeArguments(candidate, node, args, excludeArgument);
65456544
typeArgumentTypes = inferenceResult.inferredTypes;
6545+
typeArgumentsAreValid = inferenceResult.failedTypeParameterIndex < 0;
65466546
}
65476547
if (!typeArgumentsAreValid) {
65486548
break;
65496549
}
65506550
candidate = getSignatureInstantiation(candidate, typeArgumentTypes);
65516551
}
6552+
65526553
if (!checkApplicableSignature(node, args, candidate, relation, excludeArgument, /*reportErrors*/ false)) {
65536554
break;
65546555
}
6556+
65556557
var index = excludeArgument ? indexOf(excludeArgument, true) : -1;
65566558
if (index < 0) {
6559+
6560+
// Check for type arguments inferred as '{}'.
6561+
if (originalCandidate.typeParameters && inferenceResult) {
6562+
for (var i = 0, len = typeArgumentTypes.length; i < len; i++) {
6563+
6564+
if (typeArgumentTypes[i] === emptyObjectType && getInferenceCandidates(inferenceResult, i).length === 0) {
6565+
error(node, Diagnostics.Type_parameter_0_was_inferred_to_have_type,
6566+
typeToString(originalCandidate.typeParameters[i]));
6567+
}
6568+
}
6569+
}
6570+
65576571
return candidate;
65586572
}
6573+
65596574
excludeArgument[index] = false;
65606575
}
65616576

Diff for: src/compiler/core.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ module ts {
159159

160160
var hasOwnProperty = Object.prototype.hasOwnProperty;
161161

162-
export function hasProperty<T>(map: Map<T>, key: string): boolean {
162+
export function hasProperty(map: Map<any>, key: string): boolean {
163163
return hasOwnProperty.call(map, key);
164164
}
165165

Diff for: src/compiler/diagnosticInformationMap.generated.ts

+1
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ module ts {
480480
_0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: { code: 7022, category: DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer." },
481481
_0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7023, category: DiagnosticCategory.Error, key: "'{0}' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." },
482482
Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7024, category: DiagnosticCategory.Error, key: "Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." },
483+
Type_parameter_0_was_inferred_to_have_type: { code: 7025, category: DiagnosticCategory.Error, key: "Type parameter '{0}' was inferred to have type '{}'." },
483484
You_cannot_rename_this_element: { code: 8000, category: DiagnosticCategory.Error, key: "You cannot rename this element." },
484485
You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library: { code: 8001, category: DiagnosticCategory.Error, key: "You cannot rename elements that are defined in the standard TypeScript library." },
485486
yield_expressions_are_not_currently_supported: { code: 9000, category: DiagnosticCategory.Error, key: "'yield' expressions are not currently supported." },

Diff for: src/compiler/diagnosticMessages.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@
617617
},
618618
"Unterminated Unicode escape sequence.": {
619619
"category": "Error",
620-
"code": 1199
620+
"code": 1199
621621
},
622622
"Duplicate identifier '{0}'.": {
623623
"category": "Error",
@@ -1913,6 +1913,10 @@
19131913
"category": "Error",
19141914
"code": 7024
19151915
},
1916+
"Type parameter '{0}' was inferred to have type '{}'.": {
1917+
"category": "Error",
1918+
"code": 7025
1919+
},
19161920
"You cannot rename this element.": {
19171921
"category": "Error",
19181922
"code": 8000

0 commit comments

Comments
 (0)