mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-09 02:30:15 -06:00
Add new 'useUnknownInCatchVariables' flag.
This commit is contained in:
parent
67b4b9076d
commit
475e201abf
@ -8603,7 +8603,7 @@ namespace ts {
|
||||
const declaration = symbol.valueDeclaration;
|
||||
if (isCatchClauseVariableDeclarationOrBindingElement(declaration)) {
|
||||
const decl = declaration as VariableDeclaration;
|
||||
if (!decl.type) return anyType;
|
||||
if (!decl.type) return compilerOptions.useUnknownInCatchVariables ? unknownType : anyType;
|
||||
const type = getTypeOfNode(decl.type);
|
||||
// an errorType will make `checkTryStatement` issue an error
|
||||
return isTypeAny(type) || type === unknownType ? type : errorType;
|
||||
|
||||
@ -668,6 +668,14 @@ namespace ts {
|
||||
category: Diagnostics.Additional_Checks,
|
||||
description: Diagnostics.Require_undeclared_properties_from_index_signatures_to_use_element_accesses
|
||||
},
|
||||
{
|
||||
name: "useUnknownInCatchVariables",
|
||||
type: "boolean",
|
||||
affectsSemanticDiagnostics: true,
|
||||
showInSimplifiedHelpView: false,
|
||||
category: Diagnostics.Additional_Checks,
|
||||
description: Diagnostics.Type_catch_clause_variables_as_unknown_instead_of_any,
|
||||
},
|
||||
|
||||
// Module Resolution
|
||||
{
|
||||
|
||||
@ -4757,6 +4757,10 @@
|
||||
"category": "Message",
|
||||
"code": 6800
|
||||
},
|
||||
"Type catch clause variables as 'unknown' instead of 'any'.": {
|
||||
"category": "Message",
|
||||
"code": 6801
|
||||
},
|
||||
|
||||
"Variable '{0}' implicitly has an '{1}' type.": {
|
||||
"category": "Error",
|
||||
|
||||
@ -5829,6 +5829,7 @@ namespace ts {
|
||||
/* @internal */ suppressOutputPathCheck?: boolean;
|
||||
target?: ScriptTarget; // TODO: GH#18217 frequently asserted as defined
|
||||
traceResolution?: boolean;
|
||||
useUnknownInCatchVariables?: boolean;
|
||||
resolveJsonModule?: boolean;
|
||||
types?: string[];
|
||||
/** Paths used to compute primary types search locations */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user