@@ -1053,6 +1053,17 @@ namespace ts {
1053
1053
return diagnostic;
1054
1054
}
1055
1055
1056
+ function errorByThrowType(location: Node | undefined, value: Type) {
1057
+ let message = "Unknown";
1058
+ if (value.flags & TypeFlags.ThrowType) {
1059
+ value = (<ThrowType>value).value;
1060
+ }
1061
+ if (value.flags & TypeFlags.StringLiteral) {
1062
+ message = (<StringLiteralType>value).value;
1063
+ }
1064
+ error(location, Diagnostics.Type_instantiated_results_in_a_throw_type_saying_Colon_0, message);
1065
+ }
1066
+
1056
1067
function addErrorOrSuggestion(isError: boolean, diagnostic: DiagnosticWithLocation) {
1057
1068
if (isError) {
1058
1069
diagnostics.add(diagnostic);
@@ -4494,7 +4505,7 @@ namespace ts {
4494
4505
return typeToTypeNodeHelper((<SubstitutionType>type).baseType, context);
4495
4506
}
4496
4507
if (type.flags & TypeFlags.ThrowType) {
4497
- return typeToTypeNodeHelper(errorType , context);
4508
+ return typeToTypeNodeHelper(neverType , context);
4498
4509
}
4499
4510
4500
4511
return Debug.fail("Should be unreachable.");
@@ -15126,12 +15137,7 @@ namespace ts {
15126
15137
}
15127
15138
}
15128
15139
if (flags & TypeFlags.ThrowType) {
15129
- const innerType = instantiateType((<ThrowType>type).value, mapper);
15130
- let errorMessage = "Unknown";
15131
- if (innerType.flags & TypeFlags.StringLiteral) {
15132
- errorMessage = (<StringLiteralType>innerType).value;
15133
- }
15134
- error(currentNode, Diagnostics.Type_instantiated_results_in_a_throw_type_saying_Colon_0, errorMessage);
15140
+ errorByThrowType(currentNode, instantiateType((<ThrowType>type).value, mapper));
15135
15141
return errorType;
15136
15142
}
15137
15143
return type;
@@ -27798,6 +27804,9 @@ namespace ts {
27798
27804
}
27799
27805
27800
27806
const returnType = getReturnTypeOfSignature(signature);
27807
+ if (returnType.flags & TypeFlags.ThrowType) {
27808
+ errorByThrowType(node, returnType);
27809
+ }
27801
27810
// Treat any call to the global 'Symbol' function that is part of a const variable or readonly property
27802
27811
// as a fresh unique symbol literal type.
27803
27812
if (returnType.flags & TypeFlags.ESSymbolLike && isSymbolOrSymbolForCall(node)) {
0 commit comments