Skip to content

Commit 530c395

Browse files
committed
feat: add throw type check for identifier
1 parent 241cc97 commit 530c395

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/compiler/checker.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,12 @@ namespace ts {
10611061

10621062
function errorByThrowType(location: Node | undefined, type: Type) {
10631063
if (type.flags & TypeFlags.ThrowType) type = (<ThrowType>type).value;
1064-
const message = getTypeNameForErrorDisplay(type);
1064+
let message = "";
1065+
if (type.flags & TypeFlags.StringLiteral) {
1066+
message = (<StringLiteralType>type).value;
1067+
} else {
1068+
message = getTypeNameForErrorDisplay(type)
1069+
};
10651070
error(location, Diagnostics.Type_instantiated_results_in_a_throw_type_saying_Colon_0, message);
10661071
}
10671072

@@ -22485,6 +22490,7 @@ namespace ts {
2248522490
checkNestedBlockScopedBinding(node, symbol);
2248622491

2248722492
const type = getConstraintForLocation(getTypeOfSymbol(localOrExportSymbol), node);
22493+
if (type.flags & TypeFlags.ThrowType) errorByThrowType(node, type);
2248822494
const assignmentKind = getAssignmentTargetKind(node);
2248922495

2249022496
if (assignmentKind) {

0 commit comments

Comments
 (0)