@@ -1059,6 +1059,17 @@ namespace ts {
1059
1059
return diagnostic;
1060
1060
}
1061
1061
1062
+ function errorByThrowType(location: Node | undefined, value: Type) {
1063
+ let message = "Unknown";
1064
+ if (value.flags & TypeFlags.ThrowType) {
1065
+ value = (<ThrowType>value).value;
1066
+ }
1067
+ if (value.flags & TypeFlags.StringLiteral) {
1068
+ message = (<StringLiteralType>value).value;
1069
+ }
1070
+ error(location, Diagnostics.Type_instantiated_results_in_a_throw_type_saying_Colon_0, message);
1071
+ }
1072
+
1062
1073
function addErrorOrSuggestion(isError: boolean, diagnostic: DiagnosticWithLocation) {
1063
1074
if (isError) {
1064
1075
diagnostics.add(diagnostic);
@@ -4525,7 +4536,7 @@ namespace ts {
4525
4536
return typeToTypeNodeHelper((<SubstitutionType>type).baseType, context);
4526
4537
}
4527
4538
if (type.flags & TypeFlags.ThrowType) {
4528
- return typeToTypeNodeHelper(errorType , context);
4539
+ return typeToTypeNodeHelper(neverType , context);
4529
4540
}
4530
4541
4531
4542
return Debug.fail("Should be unreachable.");
@@ -15169,12 +15180,7 @@ namespace ts {
15169
15180
}
15170
15181
}
15171
15182
if (flags & TypeFlags.ThrowType) {
15172
- const innerType = instantiateType((<ThrowType>type).value, mapper);
15173
- let errorMessage = "Unknown";
15174
- if (innerType.flags & TypeFlags.StringLiteral) {
15175
- errorMessage = (<StringLiteralType>innerType).value;
15176
- }
15177
- error(currentNode, Diagnostics.Type_instantiated_results_in_a_throw_type_saying_Colon_0, errorMessage);
15183
+ errorByThrowType(currentNode, instantiateType((<ThrowType>type).value, mapper));
15178
15184
return errorType;
15179
15185
}
15180
15186
return type;
@@ -27870,6 +27876,9 @@ namespace ts {
27870
27876
}
27871
27877
27872
27878
const returnType = getReturnTypeOfSignature(signature);
27879
+ if (returnType.flags & TypeFlags.ThrowType) {
27880
+ errorByThrowType(node, returnType);
27881
+ }
27873
27882
// Treat any call to the global 'Symbol' function that is part of a const variable or readonly property
27874
27883
// as a fresh unique symbol literal type.
27875
27884
if (returnType.flags & TypeFlags.ESSymbolLike && isSymbolOrSymbolForCall(node)) {
0 commit comments