@@ -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.");
@@ -15122,12 +15133,7 @@ namespace ts {
15122
15133
}
15123
15134
}
15124
15135
if (flags & TypeFlags.ThrowType) {
15125
- const innerType = instantiateType((<ThrowType>type).value, mapper);
15126
- let errorMessage = "Unknown";
15127
- if (innerType.flags & TypeFlags.StringLiteral) {
15128
- errorMessage = (<StringLiteralType>innerType).value;
15129
- }
15130
- error(currentNode, Diagnostics.Type_instantiated_results_in_a_throw_type_saying_Colon_0, errorMessage);
15136
+ errorByThrowType(currentNode, instantiateType((<ThrowType>type).value, mapper));
15131
15137
return errorType;
15132
15138
}
15133
15139
return type;
@@ -27794,6 +27800,9 @@ namespace ts {
27794
27800
}
27795
27801
27796
27802
const returnType = getReturnTypeOfSignature(signature);
27803
+ if (returnType.flags & TypeFlags.ThrowType) {
27804
+ errorByThrowType(node, returnType);
27805
+ }
27797
27806
// Treat any call to the global 'Symbol' function that is part of a const variable or readonly property
27798
27807
// as a fresh unique symbol literal type.
27799
27808
if (returnType.flags & TypeFlags.ESSymbolLike && isSymbolOrSymbolForCall(node)) {
0 commit comments