Add related span for mixin constructor error (#28319)

* Add related span for mixin constructor error

* Remove unneeded casts

* Nicer style
This commit is contained in:
Wesley Wigham
2018-11-02 17:29:05 -07:00
committed by GitHub
parent 92a48d8880
commit eba83f4ea7
7 changed files with 150 additions and 2 deletions

View File

@@ -5674,7 +5674,18 @@ namespace ts {
return type.resolvedBaseConstructorType = errorType;
}
if (!(baseConstructorType.flags & TypeFlags.Any) && baseConstructorType !== nullWideningType && !isConstructorType(baseConstructorType)) {
error(baseTypeNode.expression, Diagnostics.Type_0_is_not_a_constructor_function_type, typeToString(baseConstructorType));
const err = error(baseTypeNode.expression, Diagnostics.Type_0_is_not_a_constructor_function_type, typeToString(baseConstructorType));
if (baseConstructorType.flags & TypeFlags.TypeParameter) {
const constraint = getConstraintFromTypeParameter(baseConstructorType);
let ctorReturn: Type = unknownType;
if (constraint) {
const ctorSig = getSignaturesOfType(constraint, SignatureKind.Construct);
if (ctorSig[0]) {
ctorReturn = getReturnTypeOfSignature(ctorSig[0]);
}
}
addRelatedInfo(err, createDiagnosticForNode(baseConstructorType.symbol.declarations[0], Diagnostics.Did_you_mean_for_0_to_be_constrained_to_type_new_args_Colon_any_1, symbolToString(baseConstructorType.symbol), typeToString(ctorReturn)));
}
return type.resolvedBaseConstructorType = errorType;
}
type.resolvedBaseConstructorType = baseConstructorType;

View File

@@ -2493,6 +2493,10 @@
"category": "Error",
"code": 2734
},
"Did you mean for '{0}' to be constrained to type 'new (...args: any[]) => {1}'?": {
"category": "Error",
"code": 2735
},
"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",