File tree Expand file tree Collapse file tree 4 files changed +14
-1
lines changed Expand file tree Collapse file tree 4 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -8603,7 +8603,7 @@ namespace ts {
86038603 const declaration = symbol.valueDeclaration;
86048604 if (isCatchClauseVariableDeclarationOrBindingElement(declaration)) {
86058605 const decl = declaration as VariableDeclaration;
8606- if (!decl.type) return anyType;
8606+ if (!decl.type) return compilerOptions.useUnknownInCatchVariables ? unknownType : anyType;
86078607 const type = getTypeOfNode(decl.type);
86088608 // an errorType will make `checkTryStatement` issue an error
86098609 return isTypeAny(type) || type === unknownType ? type : errorType;
Original file line number Diff line number Diff line change @@ -668,6 +668,14 @@ namespace ts {
668668 category : Diagnostics . Additional_Checks ,
669669 description : Diagnostics . Require_undeclared_properties_from_index_signatures_to_use_element_accesses
670670 } ,
671+ {
672+ name : "useUnknownInCatchVariables" ,
673+ type : "boolean" ,
674+ affectsSemanticDiagnostics : true ,
675+ showInSimplifiedHelpView : false ,
676+ category : Diagnostics . Additional_Checks ,
677+ description : Diagnostics . Type_catch_clause_variables_as_unknown_instead_of_any ,
678+ } ,
671679
672680 // Module Resolution
673681 {
Original file line number Diff line number Diff line change 47574757 "category" : " Message" ,
47584758 "code" : 6800
47594759 },
4760+ "Type catch clause variables as 'unknown' instead of 'any'." : {
4761+ "category" : " Message" ,
4762+ "code" : 6801
4763+ },
47604764
47614765 "Variable '{0}' implicitly has an '{1}' type." : {
47624766 "category" : " Error" ,
Original file line number Diff line number Diff line change @@ -5829,6 +5829,7 @@ namespace ts {
58295829 /* @internal */ suppressOutputPathCheck ?: boolean ;
58305830 target ?: ScriptTarget ; // TODO: GH#18217 frequently asserted as defined
58315831 traceResolution ?: boolean ;
5832+ useUnknownInCatchVariables ?: boolean ;
58325833 resolveJsonModule ?: boolean ;
58335834 types ?: string [ ] ;
58345835 /** Paths used to compute primary types search locations */
You can’t perform that action at this time.
0 commit comments