File tree 4 files changed +14
-1
lines changed
4 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -8556,7 +8556,7 @@ namespace ts {
8556
8556
const declaration = symbol.valueDeclaration;
8557
8557
if (isCatchClauseVariableDeclarationOrBindingElement(declaration)) {
8558
8558
const decl = declaration as VariableDeclaration;
8559
- if (!decl.type) return anyType;
8559
+ if (!decl.type) return compilerOptions.useUnknownInCatchVariables ? unknownType : anyType;
8560
8560
const type = getTypeOfNode(decl.type);
8561
8561
// an errorType will make `checkTryStatement` issue an error
8562
8562
return isTypeAny(type) || type === unknownType ? type : errorType;
Original file line number Diff line number Diff line change @@ -634,6 +634,14 @@ namespace ts {
634
634
category : Diagnostics . Additional_Checks ,
635
635
description : Diagnostics . Include_undefined_in_index_signature_results
636
636
} ,
637
+ {
638
+ name : "useUnknownInCatchVariables" ,
639
+ type : "boolean" ,
640
+ affectsSemanticDiagnostics : true ,
641
+ showInSimplifiedHelpView : false ,
642
+ category : Diagnostics . Additional_Checks ,
643
+ description : Diagnostics . Type_catch_clause_variables_as_unknown_instead_of_any ,
644
+ } ,
637
645
638
646
// Module Resolution
639
647
{
Original file line number Diff line number Diff line change 4742
4742
"category" : " Message" ,
4743
4743
"code" : 6800
4744
4744
},
4745
+ "Type catch clause variables as 'unknown' instead of 'any'." : {
4746
+ "category" : " Message" ,
4747
+ "code" : 6801
4748
+ },
4745
4749
4746
4750
"Variable '{0}' implicitly has an '{1}' type." : {
4747
4751
"category" : " Error" ,
Original file line number Diff line number Diff line change @@ -5819,6 +5819,7 @@ namespace ts {
5819
5819
/* @internal */ suppressOutputPathCheck ?: boolean ;
5820
5820
target ?: ScriptTarget ; // TODO: GH#18217 frequently asserted as defined
5821
5821
traceResolution ?: boolean ;
5822
+ useUnknownInCatchVariables ?: boolean ;
5822
5823
resolveJsonModule ?: boolean ;
5823
5824
types ?: string [ ] ;
5824
5825
/** Paths used to compute primary types search locations */
You can’t perform that action at this time.
0 commit comments