Skip to content

Commit 22c76cf

Browse files
committed
fix: un-instantiate throw type in return type
1 parent 1c1c653 commit 22c76cf

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/compiler/checker.ts

+6-10
Original file line numberDiff line numberDiff line change
@@ -1059,14 +1059,9 @@ namespace ts {
10591059
return diagnostic;
10601060
}
10611061

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-
}
1062+
function errorByThrowType(location: Node | undefined, type: Type) {
1063+
if (type.flags & TypeFlags.ThrowType) type = (<ThrowType>type).value;
1064+
const message = getTypeNameForErrorDisplay(type);
10701065
error(location, Diagnostics.Type_instantiated_results_in_a_throw_type_saying_Colon_0, message);
10711066
}
10721067

@@ -15118,6 +15113,7 @@ namespace ts {
1511815113
function instantiateType(type: Type | undefined, mapper: TypeMapper | undefined): Type | undefined;
1511915114
function instantiateType(type: Type | undefined, mapper: TypeMapper | undefined): Type | undefined {
1512015115
if (!(type && mapper && couldContainTypeVariables(type))) {
15116+
if (type && (type.flags & TypeFlags.ThrowType)) errorByThrowType(currentNode, type);
1512115117
return type;
1512215118
}
1512315119
if (instantiationDepth === 50 || instantiationCount >= 5000000) {
@@ -15186,8 +15182,8 @@ namespace ts {
1518615182
}
1518715183
}
1518815184
if (flags & TypeFlags.ThrowType) {
15189-
errorByThrowType(currentNode, instantiateType((<ThrowType>type).value, mapper));
15190-
return errorType;
15185+
const errorMessage = instantiateType((<ThrowType>type).value, mapper);
15186+
return createThrowType(errorMessage);
1519115187
}
1519215188
return type;
1519315189
}

0 commit comments

Comments
 (0)