Make catch clause checking consistent with variable declarations (#52240)

This commit is contained in:
Jake Bailey 2023-01-19 11:56:37 -08:00 коммит произвёл GitHub
Родитель ecaf6d91a7
Коммит b7f619d25e
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
30 изменённых файлов: 1719 добавлений и 42 удалений

Просмотреть файл

@ -10219,6 +10219,15 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// Use type from type annotation if one is present
const declaredType = tryGetTypeFromEffectiveTypeNode(declaration);
if (isCatchClauseVariableDeclarationOrBindingElement(declaration)) {
if (declaredType) {
// If the catch clause is explicitly annotated with any or unknown, accept it, otherwise error.
return isTypeAny(declaredType) || declaredType === unknownType ? declaredType : errorType;
}
// If the catch clause is not explicitly annotated, treat it as though it were explicitly
// annotated with unknown or any, depending on useUnknownInCatchVariables.
return useUnknownInCatchVariables ? unknownType : anyType;
}
if (declaredType) {
return addOptionality(declaredType, isProperty, isOptional);
}
@ -10877,18 +10886,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
members.set("exports" as __String, result);
return createAnonymousType(symbol, members, emptyArray, emptyArray, emptyArray);
}
// Handle catch clause variables
Debug.assertIsDefined(symbol.valueDeclaration);
const declaration = symbol.valueDeclaration;
if (isCatchClauseVariableDeclarationOrBindingElement(declaration)) {
const typeNode = getEffectiveTypeAnnotationNode(declaration);
if (typeNode === undefined) {
return useUnknownInCatchVariables ? unknownType : anyType;
}
const type = getTypeOfNode(typeNode);
// an errorType will make `checkTryStatement` issue an error
return isTypeAny(type) || type === unknownType ? type : errorType;
}
// Handle export default expressions
if (isSourceFile(declaration) && isJsonSourceFile(declaration)) {
if (!declaration.statements.length) {
@ -27079,6 +27078,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
isFunctionLike(node) && !getImmediatelyInvokedFunctionExpression(node) ||
node.kind === SyntaxKind.ModuleBlock ||
node.kind === SyntaxKind.SourceFile ||
node.kind === SyntaxKind.CatchClause ||
node.kind === SyntaxKind.PropertyDeclaration)!;
}
@ -27451,6 +27451,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const isParameter = getRootDeclaration(declaration).kind === SyntaxKind.Parameter;
const declarationContainer = getControlFlowContainer(declaration);
let flowContainer = getControlFlowContainer(node);
const isCatch = flowContainer.kind === SyntaxKind.CatchClause;
const isOuterVariable = flowContainer !== declarationContainer;
const isSpreadDestructuringAssignmentTarget = node.parent && node.parent.parent && isSpreadAssignment(node.parent) && isDestructuringAssignmentTarget(node.parent.parent);
const isModuleExports = symbol.flags & SymbolFlags.ModuleExports;
@ -27465,7 +27466,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// We only look for uninitialized variables in strict null checking mode, and only when we can analyze
// the entire control flow graph from the variable's declaration (i.e. when the flow container and
// declaration container are the same).
const assumeInitialized = isParameter || isAlias || isOuterVariable || isSpreadDestructuringAssignmentTarget || isModuleExports || isSameScopedBindingElement(node, declaration) ||
const assumeInitialized = isParameter || isCatch || isAlias || isOuterVariable || isSpreadDestructuringAssignmentTarget || isModuleExports || isSameScopedBindingElement(node, declaration) ||
type !== autoType && type !== autoArrayType && (!strictNullChecks || (type.flags & (TypeFlags.AnyOrUnknown | TypeFlags.Void)) !== 0 ||
isInTypeQuery(node) || isInAmbientOrTypeNode(node) || node.parent.kind === SyntaxKind.ExportSpecifier) ||
node.parent.kind === SyntaxKind.NonNullExpression ||
@ -41230,9 +41231,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// Grammar checking
if (catchClause.variableDeclaration) {
const declaration = catchClause.variableDeclaration;
const typeNode = getEffectiveTypeAnnotationNode(getRootDeclaration(declaration));
checkVariableLikeDeclaration(declaration);
const typeNode = getEffectiveTypeAnnotationNode(declaration);
if (typeNode) {
const type = getTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ false, CheckMode.Normal);
const type = getTypeFromTypeNode(typeNode);
if (type && !(type.flags & TypeFlags.AnyOrUnknown)) {
grammarErrorOnFirstToken(typeNode, Diagnostics.Catch_clause_variable_type_annotation_must_be_any_or_unknown_if_specified);
}

Просмотреть файл

@ -4,11 +4,13 @@ tests/cases/conformance/statements/tryStatements/catchClauseWithTypeAnnotation.t
tests/cases/conformance/statements/tryStatements/catchClauseWithTypeAnnotation.ts(20,23): error TS1196: Catch clause variable type annotation must be 'any' or 'unknown' if specified.
tests/cases/conformance/statements/tryStatements/catchClauseWithTypeAnnotation.ts(29,29): error TS2492: Cannot redeclare identifier 'x' in catch clause.
tests/cases/conformance/statements/tryStatements/catchClauseWithTypeAnnotation.ts(30,29): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'boolean', but here has type 'string'.
tests/cases/conformance/statements/tryStatements/catchClauseWithTypeAnnotation.ts(36,22): error TS2339: Property 'x' does not exist on type '{}'.
tests/cases/conformance/statements/tryStatements/catchClauseWithTypeAnnotation.ts(37,22): error TS2339: Property 'x' does not exist on type '{}'.
tests/cases/conformance/statements/tryStatements/catchClauseWithTypeAnnotation.ts(38,27): error TS1196: Catch clause variable type annotation must be 'any' or 'unknown' if specified.
tests/cases/conformance/statements/tryStatements/catchClauseWithTypeAnnotation.ts(39,27): error TS1196: Catch clause variable type annotation must be 'any' or 'unknown' if specified.
==== tests/cases/conformance/statements/tryStatements/catchClauseWithTypeAnnotation.ts (8 errors) ====
==== tests/cases/conformance/statements/tryStatements/catchClauseWithTypeAnnotation.ts (10 errors) ====
type any1 = any;
type unknown1 = unknown;
@ -57,8 +59,12 @@ tests/cases/conformance/statements/tryStatements/catchClauseWithTypeAnnotation.t
try { } catch ({ x }) { } // should be OK
try { } catch ({ x }: any) { x.foo; } // should be OK
try { } catch ({ x }: any1) { x.foo;} // should be OK
try { } catch ({ x }: unknown) { console.log(x); } // should be OK
try { } catch ({ x }: unknown1) { console.log(x); } // should be OK
try { } catch ({ x }: unknown) { console.log(x); } // error in the destructure
~
!!! error TS2339: Property 'x' does not exist on type '{}'.
try { } catch ({ x }: unknown1) { console.log(x); } // error in the destructure
~
!!! error TS2339: Property 'x' does not exist on type '{}'.
try { } catch ({ x }: object) { } // error in the type
~~~~~~
!!! error TS1196: Catch clause variable type annotation must be 'any' or 'unknown' if specified.

Просмотреть файл

@ -34,8 +34,8 @@ function fn(x: boolean) {
try { } catch ({ x }) { } // should be OK
try { } catch ({ x }: any) { x.foo; } // should be OK
try { } catch ({ x }: any1) { x.foo;} // should be OK
try { } catch ({ x }: unknown) { console.log(x); } // should be OK
try { } catch ({ x }: unknown1) { console.log(x); } // should be OK
try { } catch ({ x }: unknown) { console.log(x); } // error in the destructure
try { } catch ({ x }: unknown1) { console.log(x); } // error in the destructure
try { } catch ({ x }: object) { } // error in the type
try { } catch ({ x }: Error) { } // error in the type
}
@ -124,12 +124,12 @@ function fn(x) {
catch (_d) {
var x_5 = _d.x;
console.log(x_5);
} // should be OK
} // error in the destructure
try { }
catch (_e) {
var x_6 = _e.x;
console.log(x_6);
} // should be OK
} // error in the destructure
try { }
catch (_f) {
var x_7 = _f.x;

Просмотреть файл

@ -112,14 +112,14 @@ function fn(x: boolean) {
>any1 : Symbol(any1, Decl(catchClauseWithTypeAnnotation.ts, 0, 0))
>x : Symbol(x, Decl(catchClauseWithTypeAnnotation.ts, 34, 20))
try { } catch ({ x }: unknown) { console.log(x); } // should be OK
try { } catch ({ x }: unknown) { console.log(x); } // error in the destructure
>x : Symbol(x, Decl(catchClauseWithTypeAnnotation.ts, 35, 20))
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>x : Symbol(x, Decl(catchClauseWithTypeAnnotation.ts, 35, 20))
try { } catch ({ x }: unknown1) { console.log(x); } // should be OK
try { } catch ({ x }: unknown1) { console.log(x); } // error in the destructure
>x : Symbol(x, Decl(catchClauseWithTypeAnnotation.ts, 36, 20))
>unknown1 : Symbol(unknown1, Decl(catchClauseWithTypeAnnotation.ts, 0, 16))
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))

Просмотреть файл

@ -126,7 +126,7 @@ function fn(x: boolean) {
>x : any
>foo : any
try { } catch ({ x }: unknown) { console.log(x); } // should be OK
try { } catch ({ x }: unknown) { console.log(x); } // error in the destructure
>x : any
>console.log(x) : void
>console.log : (...data: any[]) => void
@ -134,7 +134,7 @@ function fn(x: boolean) {
>log : (...data: any[]) => void
>x : any
try { } catch ({ x }: unknown1) { console.log(x); } // should be OK
try { } catch ({ x }: unknown1) { console.log(x); } // error in the destructure
>x : any
>console.log(x) : void
>console.log : (...data: any[]) => void

Просмотреть файл

@ -0,0 +1,60 @@
tests/cases/compiler/destructureCatchClause.ts(26,17): error TS2339: Property 'x' does not exist on type '{}'.
tests/cases/compiler/destructureCatchClause.ts(27,15): error TS2461: Type 'unknown' is not an array type.
tests/cases/compiler/destructureCatchClause.ts(29,17): error TS2339: Property 'a' does not exist on type '{}'.
tests/cases/compiler/destructureCatchClause.ts(30,17): error TS2339: Property 'a' does not exist on type '{}'.
tests/cases/compiler/destructureCatchClause.ts(32,15): error TS2461: Type 'unknown' is not an array type.
tests/cases/compiler/destructureCatchClause.ts(33,15): error TS2461: Type 'unknown' is not an array type.
tests/cases/compiler/destructureCatchClause.ts(35,17): error TS2339: Property 'a' does not exist on type '{}'.
==== tests/cases/compiler/destructureCatchClause.ts (7 errors) ====
// These are okay with useUnknownInCatchVariables=false, but not okay with useUnknownInCatchVariables=true.
try {} catch ({ x }) { x }
try {} catch ([ x ]) { x }
try {} catch ({ a: { x } }) { x }
try {} catch ({ a: [ x ] }) { x }
try {} catch ([{ x }]) { x }
try {} catch ([[ x ]]) { x }
try {} catch ({ a: { b: { c: { x }} }}) { x }
try {} catch ({ x }: any) { x }
try {} catch ([ x ]: any) { x }
try {} catch ({ a: { x } }: any) { x }
try {} catch ({ a: [ x ] }: any) { x }
try {} catch ([{ x }]: any) { x }
try {} catch ([[ x ]]: any) { x }
try {} catch ({ a: { b: { c: { x }} }}: any) { x }
try {} catch ({ x }: unknown) { x }
~
!!! error TS2339: Property 'x' does not exist on type '{}'.
try {} catch ([ x ]: unknown) { x }
~~~~~
!!! error TS2461: Type 'unknown' is not an array type.
try {} catch ({ a: { x } }: unknown) { x }
~
!!! error TS2339: Property 'a' does not exist on type '{}'.
try {} catch ({ a: [ x ] }: unknown) { x }
~
!!! error TS2339: Property 'a' does not exist on type '{}'.
try {} catch ([{ x }]: unknown) { x }
~~~~~~~
!!! error TS2461: Type 'unknown' is not an array type.
try {} catch ([[ x ]]: unknown) { x }
~~~~~~~
!!! error TS2461: Type 'unknown' is not an array type.
try {} catch ({ a: { b: { c: { x }} }}: unknown) { x }
~
!!! error TS2339: Property 'a' does not exist on type '{}'.

Просмотреть файл

@ -0,0 +1,145 @@
//// [destructureCatchClause.ts]
// These are okay with useUnknownInCatchVariables=false, but not okay with useUnknownInCatchVariables=true.
try {} catch ({ x }) { x }
try {} catch ([ x ]) { x }
try {} catch ({ a: { x } }) { x }
try {} catch ({ a: [ x ] }) { x }
try {} catch ([{ x }]) { x }
try {} catch ([[ x ]]) { x }
try {} catch ({ a: { b: { c: { x }} }}) { x }
try {} catch ({ x }: any) { x }
try {} catch ([ x ]: any) { x }
try {} catch ({ a: { x } }: any) { x }
try {} catch ({ a: [ x ] }: any) { x }
try {} catch ([{ x }]: any) { x }
try {} catch ([[ x ]]: any) { x }
try {} catch ({ a: { b: { c: { x }} }}: any) { x }
try {} catch ({ x }: unknown) { x }
try {} catch ([ x ]: unknown) { x }
try {} catch ({ a: { x } }: unknown) { x }
try {} catch ({ a: [ x ] }: unknown) { x }
try {} catch ([{ x }]: unknown) { x }
try {} catch ([[ x ]]: unknown) { x }
try {} catch ({ a: { b: { c: { x }} }}: unknown) { x }
//// [destructureCatchClause.js]
// These are okay with useUnknownInCatchVariables=false, but not okay with useUnknownInCatchVariables=true.
try { }
catch (_a) {
var x = _a.x;
x;
}
try { }
catch (_b) {
var x = _b[0];
x;
}
try { }
catch (_c) {
var x = _c.a.x;
x;
}
try { }
catch (_d) {
var x = _d.a[0];
x;
}
try { }
catch (_e) {
var x = _e[0].x;
x;
}
try { }
catch (_f) {
var x = _f[0][0];
x;
}
try { }
catch (_g) {
var x = _g.a.b.c.x;
x;
}
try { }
catch (_h) {
var x = _h.x;
x;
}
try { }
catch (_j) {
var x = _j[0];
x;
}
try { }
catch (_k) {
var x = _k.a.x;
x;
}
try { }
catch (_l) {
var x = _l.a[0];
x;
}
try { }
catch (_m) {
var x = _m[0].x;
x;
}
try { }
catch (_o) {
var x = _o[0][0];
x;
}
try { }
catch (_p) {
var x = _p.a.b.c.x;
x;
}
try { }
catch (_q) {
var x = _q.x;
x;
}
try { }
catch (_r) {
var x = _r[0];
x;
}
try { }
catch (_s) {
var x = _s.a.x;
x;
}
try { }
catch (_t) {
var x = _t.a[0];
x;
}
try { }
catch (_u) {
var x = _u[0].x;
x;
}
try { }
catch (_v) {
var x = _v[0][0];
x;
}
try { }
catch (_w) {
var x = _w.a.b.c.x;
x;
}

Просмотреть файл

@ -0,0 +1,88 @@
=== tests/cases/compiler/destructureCatchClause.ts ===
// These are okay with useUnknownInCatchVariables=false, but not okay with useUnknownInCatchVariables=true.
try {} catch ({ x }) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 1, 15))
>x : Symbol(x, Decl(destructureCatchClause.ts, 1, 15))
try {} catch ([ x ]) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 2, 15))
>x : Symbol(x, Decl(destructureCatchClause.ts, 2, 15))
try {} catch ({ a: { x } }) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 4, 20))
>x : Symbol(x, Decl(destructureCatchClause.ts, 4, 20))
try {} catch ({ a: [ x ] }) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 5, 20))
>x : Symbol(x, Decl(destructureCatchClause.ts, 5, 20))
try {} catch ([{ x }]) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 7, 16))
>x : Symbol(x, Decl(destructureCatchClause.ts, 7, 16))
try {} catch ([[ x ]]) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 8, 16))
>x : Symbol(x, Decl(destructureCatchClause.ts, 8, 16))
try {} catch ({ a: { b: { c: { x }} }}) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 10, 30))
>x : Symbol(x, Decl(destructureCatchClause.ts, 10, 30))
try {} catch ({ x }: any) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 13, 15))
>x : Symbol(x, Decl(destructureCatchClause.ts, 13, 15))
try {} catch ([ x ]: any) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 14, 15))
>x : Symbol(x, Decl(destructureCatchClause.ts, 14, 15))
try {} catch ({ a: { x } }: any) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 16, 20))
>x : Symbol(x, Decl(destructureCatchClause.ts, 16, 20))
try {} catch ({ a: [ x ] }: any) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 17, 20))
>x : Symbol(x, Decl(destructureCatchClause.ts, 17, 20))
try {} catch ([{ x }]: any) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 19, 16))
>x : Symbol(x, Decl(destructureCatchClause.ts, 19, 16))
try {} catch ([[ x ]]: any) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 20, 16))
>x : Symbol(x, Decl(destructureCatchClause.ts, 20, 16))
try {} catch ({ a: { b: { c: { x }} }}: any) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 22, 30))
>x : Symbol(x, Decl(destructureCatchClause.ts, 22, 30))
try {} catch ({ x }: unknown) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 25, 15))
>x : Symbol(x, Decl(destructureCatchClause.ts, 25, 15))
try {} catch ([ x ]: unknown) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 26, 15))
>x : Symbol(x, Decl(destructureCatchClause.ts, 26, 15))
try {} catch ({ a: { x } }: unknown) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 28, 20))
>x : Symbol(x, Decl(destructureCatchClause.ts, 28, 20))
try {} catch ({ a: [ x ] }: unknown) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 29, 20))
>x : Symbol(x, Decl(destructureCatchClause.ts, 29, 20))
try {} catch ([{ x }]: unknown) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 31, 16))
>x : Symbol(x, Decl(destructureCatchClause.ts, 31, 16))
try {} catch ([[ x ]]: unknown) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 32, 16))
>x : Symbol(x, Decl(destructureCatchClause.ts, 32, 16))
try {} catch ({ a: { b: { c: { x }} }}: unknown) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 34, 30))
>x : Symbol(x, Decl(destructureCatchClause.ts, 34, 30))

Просмотреть файл

@ -0,0 +1,103 @@
=== tests/cases/compiler/destructureCatchClause.ts ===
// These are okay with useUnknownInCatchVariables=false, but not okay with useUnknownInCatchVariables=true.
try {} catch ({ x }) { x }
>x : any
>x : any
try {} catch ([ x ]) { x }
>x : any
>x : any
try {} catch ({ a: { x } }) { x }
>a : any
>x : any
>x : any
try {} catch ({ a: [ x ] }) { x }
>a : any
>x : any
>x : any
try {} catch ([{ x }]) { x }
>x : any
>x : any
try {} catch ([[ x ]]) { x }
>x : any
>x : any
try {} catch ({ a: { b: { c: { x }} }}) { x }
>a : any
>b : any
>c : any
>x : any
>x : any
try {} catch ({ x }: any) { x }
>x : any
>x : any
try {} catch ([ x ]: any) { x }
>x : any
>x : any
try {} catch ({ a: { x } }: any) { x }
>a : any
>x : any
>x : any
try {} catch ({ a: [ x ] }: any) { x }
>a : any
>x : any
>x : any
try {} catch ([{ x }]: any) { x }
>x : any
>x : any
try {} catch ([[ x ]]: any) { x }
>x : any
>x : any
try {} catch ({ a: { b: { c: { x }} }}: any) { x }
>a : any
>b : any
>c : any
>x : any
>x : any
try {} catch ({ x }: unknown) { x }
>x : any
>x : any
try {} catch ([ x ]: unknown) { x }
>x : any
>x : any
try {} catch ({ a: { x } }: unknown) { x }
>a : any
>x : any
>x : any
try {} catch ({ a: [ x ] }: unknown) { x }
>a : any
>x : any
>x : any
try {} catch ([{ x }]: unknown) { x }
>x : any
>x : any
try {} catch ([[ x ]]: unknown) { x }
>x : any
>x : any
try {} catch ({ a: { b: { c: { x }} }}: unknown) { x }
>a : any
>b : any
>c : any
>x : any
>x : any

Просмотреть файл

@ -0,0 +1,81 @@
tests/cases/compiler/destructureCatchClause.ts(2,17): error TS2339: Property 'x' does not exist on type '{}'.
tests/cases/compiler/destructureCatchClause.ts(3,15): error TS2461: Type 'unknown' is not an array type.
tests/cases/compiler/destructureCatchClause.ts(5,17): error TS2339: Property 'a' does not exist on type '{}'.
tests/cases/compiler/destructureCatchClause.ts(6,17): error TS2339: Property 'a' does not exist on type '{}'.
tests/cases/compiler/destructureCatchClause.ts(8,15): error TS2461: Type 'unknown' is not an array type.
tests/cases/compiler/destructureCatchClause.ts(9,15): error TS2461: Type 'unknown' is not an array type.
tests/cases/compiler/destructureCatchClause.ts(11,17): error TS2339: Property 'a' does not exist on type '{}'.
tests/cases/compiler/destructureCatchClause.ts(26,17): error TS2339: Property 'x' does not exist on type '{}'.
tests/cases/compiler/destructureCatchClause.ts(27,15): error TS2461: Type 'unknown' is not an array type.
tests/cases/compiler/destructureCatchClause.ts(29,17): error TS2339: Property 'a' does not exist on type '{}'.
tests/cases/compiler/destructureCatchClause.ts(30,17): error TS2339: Property 'a' does not exist on type '{}'.
tests/cases/compiler/destructureCatchClause.ts(32,15): error TS2461: Type 'unknown' is not an array type.
tests/cases/compiler/destructureCatchClause.ts(33,15): error TS2461: Type 'unknown' is not an array type.
tests/cases/compiler/destructureCatchClause.ts(35,17): error TS2339: Property 'a' does not exist on type '{}'.
==== tests/cases/compiler/destructureCatchClause.ts (14 errors) ====
// These are okay with useUnknownInCatchVariables=false, but not okay with useUnknownInCatchVariables=true.
try {} catch ({ x }) { x }
~
!!! error TS2339: Property 'x' does not exist on type '{}'.
try {} catch ([ x ]) { x }
~~~~~
!!! error TS2461: Type 'unknown' is not an array type.
try {} catch ({ a: { x } }) { x }
~
!!! error TS2339: Property 'a' does not exist on type '{}'.
try {} catch ({ a: [ x ] }) { x }
~
!!! error TS2339: Property 'a' does not exist on type '{}'.
try {} catch ([{ x }]) { x }
~~~~~~~
!!! error TS2461: Type 'unknown' is not an array type.
try {} catch ([[ x ]]) { x }
~~~~~~~
!!! error TS2461: Type 'unknown' is not an array type.
try {} catch ({ a: { b: { c: { x }} }}) { x }
~
!!! error TS2339: Property 'a' does not exist on type '{}'.
try {} catch ({ x }: any) { x }
try {} catch ([ x ]: any) { x }
try {} catch ({ a: { x } }: any) { x }
try {} catch ({ a: [ x ] }: any) { x }
try {} catch ([{ x }]: any) { x }
try {} catch ([[ x ]]: any) { x }
try {} catch ({ a: { b: { c: { x }} }}: any) { x }
try {} catch ({ x }: unknown) { x }
~
!!! error TS2339: Property 'x' does not exist on type '{}'.
try {} catch ([ x ]: unknown) { x }
~~~~~
!!! error TS2461: Type 'unknown' is not an array type.
try {} catch ({ a: { x } }: unknown) { x }
~
!!! error TS2339: Property 'a' does not exist on type '{}'.
try {} catch ({ a: [ x ] }: unknown) { x }
~
!!! error TS2339: Property 'a' does not exist on type '{}'.
try {} catch ([{ x }]: unknown) { x }
~~~~~~~
!!! error TS2461: Type 'unknown' is not an array type.
try {} catch ([[ x ]]: unknown) { x }
~~~~~~~
!!! error TS2461: Type 'unknown' is not an array type.
try {} catch ({ a: { b: { c: { x }} }}: unknown) { x }
~
!!! error TS2339: Property 'a' does not exist on type '{}'.

Просмотреть файл

@ -0,0 +1,145 @@
//// [destructureCatchClause.ts]
// These are okay with useUnknownInCatchVariables=false, but not okay with useUnknownInCatchVariables=true.
try {} catch ({ x }) { x }
try {} catch ([ x ]) { x }
try {} catch ({ a: { x } }) { x }
try {} catch ({ a: [ x ] }) { x }
try {} catch ([{ x }]) { x }
try {} catch ([[ x ]]) { x }
try {} catch ({ a: { b: { c: { x }} }}) { x }
try {} catch ({ x }: any) { x }
try {} catch ([ x ]: any) { x }
try {} catch ({ a: { x } }: any) { x }
try {} catch ({ a: [ x ] }: any) { x }
try {} catch ([{ x }]: any) { x }
try {} catch ([[ x ]]: any) { x }
try {} catch ({ a: { b: { c: { x }} }}: any) { x }
try {} catch ({ x }: unknown) { x }
try {} catch ([ x ]: unknown) { x }
try {} catch ({ a: { x } }: unknown) { x }
try {} catch ({ a: [ x ] }: unknown) { x }
try {} catch ([{ x }]: unknown) { x }
try {} catch ([[ x ]]: unknown) { x }
try {} catch ({ a: { b: { c: { x }} }}: unknown) { x }
//// [destructureCatchClause.js]
// These are okay with useUnknownInCatchVariables=false, but not okay with useUnknownInCatchVariables=true.
try { }
catch (_a) {
var x = _a.x;
x;
}
try { }
catch (_b) {
var x = _b[0];
x;
}
try { }
catch (_c) {
var x = _c.a.x;
x;
}
try { }
catch (_d) {
var x = _d.a[0];
x;
}
try { }
catch (_e) {
var x = _e[0].x;
x;
}
try { }
catch (_f) {
var x = _f[0][0];
x;
}
try { }
catch (_g) {
var x = _g.a.b.c.x;
x;
}
try { }
catch (_h) {
var x = _h.x;
x;
}
try { }
catch (_j) {
var x = _j[0];
x;
}
try { }
catch (_k) {
var x = _k.a.x;
x;
}
try { }
catch (_l) {
var x = _l.a[0];
x;
}
try { }
catch (_m) {
var x = _m[0].x;
x;
}
try { }
catch (_o) {
var x = _o[0][0];
x;
}
try { }
catch (_p) {
var x = _p.a.b.c.x;
x;
}
try { }
catch (_q) {
var x = _q.x;
x;
}
try { }
catch (_r) {
var x = _r[0];
x;
}
try { }
catch (_s) {
var x = _s.a.x;
x;
}
try { }
catch (_t) {
var x = _t.a[0];
x;
}
try { }
catch (_u) {
var x = _u[0].x;
x;
}
try { }
catch (_v) {
var x = _v[0][0];
x;
}
try { }
catch (_w) {
var x = _w.a.b.c.x;
x;
}

Просмотреть файл

@ -0,0 +1,88 @@
=== tests/cases/compiler/destructureCatchClause.ts ===
// These are okay with useUnknownInCatchVariables=false, but not okay with useUnknownInCatchVariables=true.
try {} catch ({ x }) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 1, 15))
>x : Symbol(x, Decl(destructureCatchClause.ts, 1, 15))
try {} catch ([ x ]) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 2, 15))
>x : Symbol(x, Decl(destructureCatchClause.ts, 2, 15))
try {} catch ({ a: { x } }) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 4, 20))
>x : Symbol(x, Decl(destructureCatchClause.ts, 4, 20))
try {} catch ({ a: [ x ] }) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 5, 20))
>x : Symbol(x, Decl(destructureCatchClause.ts, 5, 20))
try {} catch ([{ x }]) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 7, 16))
>x : Symbol(x, Decl(destructureCatchClause.ts, 7, 16))
try {} catch ([[ x ]]) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 8, 16))
>x : Symbol(x, Decl(destructureCatchClause.ts, 8, 16))
try {} catch ({ a: { b: { c: { x }} }}) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 10, 30))
>x : Symbol(x, Decl(destructureCatchClause.ts, 10, 30))
try {} catch ({ x }: any) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 13, 15))
>x : Symbol(x, Decl(destructureCatchClause.ts, 13, 15))
try {} catch ([ x ]: any) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 14, 15))
>x : Symbol(x, Decl(destructureCatchClause.ts, 14, 15))
try {} catch ({ a: { x } }: any) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 16, 20))
>x : Symbol(x, Decl(destructureCatchClause.ts, 16, 20))
try {} catch ({ a: [ x ] }: any) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 17, 20))
>x : Symbol(x, Decl(destructureCatchClause.ts, 17, 20))
try {} catch ([{ x }]: any) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 19, 16))
>x : Symbol(x, Decl(destructureCatchClause.ts, 19, 16))
try {} catch ([[ x ]]: any) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 20, 16))
>x : Symbol(x, Decl(destructureCatchClause.ts, 20, 16))
try {} catch ({ a: { b: { c: { x }} }}: any) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 22, 30))
>x : Symbol(x, Decl(destructureCatchClause.ts, 22, 30))
try {} catch ({ x }: unknown) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 25, 15))
>x : Symbol(x, Decl(destructureCatchClause.ts, 25, 15))
try {} catch ([ x ]: unknown) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 26, 15))
>x : Symbol(x, Decl(destructureCatchClause.ts, 26, 15))
try {} catch ({ a: { x } }: unknown) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 28, 20))
>x : Symbol(x, Decl(destructureCatchClause.ts, 28, 20))
try {} catch ({ a: [ x ] }: unknown) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 29, 20))
>x : Symbol(x, Decl(destructureCatchClause.ts, 29, 20))
try {} catch ([{ x }]: unknown) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 31, 16))
>x : Symbol(x, Decl(destructureCatchClause.ts, 31, 16))
try {} catch ([[ x ]]: unknown) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 32, 16))
>x : Symbol(x, Decl(destructureCatchClause.ts, 32, 16))
try {} catch ({ a: { b: { c: { x }} }}: unknown) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 34, 30))
>x : Symbol(x, Decl(destructureCatchClause.ts, 34, 30))

Просмотреть файл

@ -0,0 +1,103 @@
=== tests/cases/compiler/destructureCatchClause.ts ===
// These are okay with useUnknownInCatchVariables=false, but not okay with useUnknownInCatchVariables=true.
try {} catch ({ x }) { x }
>x : any
>x : any
try {} catch ([ x ]) { x }
>x : any
>x : any
try {} catch ({ a: { x } }) { x }
>a : any
>x : any
>x : any
try {} catch ({ a: [ x ] }) { x }
>a : any
>x : any
>x : any
try {} catch ([{ x }]) { x }
>x : any
>x : any
try {} catch ([[ x ]]) { x }
>x : any
>x : any
try {} catch ({ a: { b: { c: { x }} }}) { x }
>a : any
>b : any
>c : any
>x : any
>x : any
try {} catch ({ x }: any) { x }
>x : any
>x : any
try {} catch ([ x ]: any) { x }
>x : any
>x : any
try {} catch ({ a: { x } }: any) { x }
>a : any
>x : any
>x : any
try {} catch ({ a: [ x ] }: any) { x }
>a : any
>x : any
>x : any
try {} catch ([{ x }]: any) { x }
>x : any
>x : any
try {} catch ([[ x ]]: any) { x }
>x : any
>x : any
try {} catch ({ a: { b: { c: { x }} }}: any) { x }
>a : any
>b : any
>c : any
>x : any
>x : any
try {} catch ({ x }: unknown) { x }
>x : any
>x : any
try {} catch ([ x ]: unknown) { x }
>x : any
>x : any
try {} catch ({ a: { x } }: unknown) { x }
>a : any
>x : any
>x : any
try {} catch ({ a: [ x ] }: unknown) { x }
>a : any
>x : any
>x : any
try {} catch ([{ x }]: unknown) { x }
>x : any
>x : any
try {} catch ([[ x ]]: unknown) { x }
>x : any
>x : any
try {} catch ({ a: { b: { c: { x }} }}: unknown) { x }
>a : any
>b : any
>c : any
>x : any
>x : any

Просмотреть файл

@ -0,0 +1,60 @@
tests/cases/compiler/destructureCatchClause.ts(26,17): error TS2339: Property 'x' does not exist on type 'unknown'.
tests/cases/compiler/destructureCatchClause.ts(27,15): error TS2461: Type 'unknown' is not an array type.
tests/cases/compiler/destructureCatchClause.ts(29,17): error TS2339: Property 'a' does not exist on type 'unknown'.
tests/cases/compiler/destructureCatchClause.ts(30,17): error TS2339: Property 'a' does not exist on type 'unknown'.
tests/cases/compiler/destructureCatchClause.ts(32,15): error TS2461: Type 'unknown' is not an array type.
tests/cases/compiler/destructureCatchClause.ts(33,15): error TS2461: Type 'unknown' is not an array type.
tests/cases/compiler/destructureCatchClause.ts(35,17): error TS2339: Property 'a' does not exist on type 'unknown'.
==== tests/cases/compiler/destructureCatchClause.ts (7 errors) ====
// These are okay with useUnknownInCatchVariables=false, but not okay with useUnknownInCatchVariables=true.
try {} catch ({ x }) { x }
try {} catch ([ x ]) { x }
try {} catch ({ a: { x } }) { x }
try {} catch ({ a: [ x ] }) { x }
try {} catch ([{ x }]) { x }
try {} catch ([[ x ]]) { x }
try {} catch ({ a: { b: { c: { x }} }}) { x }
try {} catch ({ x }: any) { x }
try {} catch ([ x ]: any) { x }
try {} catch ({ a: { x } }: any) { x }
try {} catch ({ a: [ x ] }: any) { x }
try {} catch ([{ x }]: any) { x }
try {} catch ([[ x ]]: any) { x }
try {} catch ({ a: { b: { c: { x }} }}: any) { x }
try {} catch ({ x }: unknown) { x }
~
!!! error TS2339: Property 'x' does not exist on type 'unknown'.
try {} catch ([ x ]: unknown) { x }
~~~~~
!!! error TS2461: Type 'unknown' is not an array type.
try {} catch ({ a: { x } }: unknown) { x }
~
!!! error TS2339: Property 'a' does not exist on type 'unknown'.
try {} catch ({ a: [ x ] }: unknown) { x }
~
!!! error TS2339: Property 'a' does not exist on type 'unknown'.
try {} catch ([{ x }]: unknown) { x }
~~~~~~~
!!! error TS2461: Type 'unknown' is not an array type.
try {} catch ([[ x ]]: unknown) { x }
~~~~~~~
!!! error TS2461: Type 'unknown' is not an array type.
try {} catch ({ a: { b: { c: { x }} }}: unknown) { x }
~
!!! error TS2339: Property 'a' does not exist on type 'unknown'.

Просмотреть файл

@ -0,0 +1,146 @@
//// [destructureCatchClause.ts]
// These are okay with useUnknownInCatchVariables=false, but not okay with useUnknownInCatchVariables=true.
try {} catch ({ x }) { x }
try {} catch ([ x ]) { x }
try {} catch ({ a: { x } }) { x }
try {} catch ({ a: [ x ] }) { x }
try {} catch ([{ x }]) { x }
try {} catch ([[ x ]]) { x }
try {} catch ({ a: { b: { c: { x }} }}) { x }
try {} catch ({ x }: any) { x }
try {} catch ([ x ]: any) { x }
try {} catch ({ a: { x } }: any) { x }
try {} catch ({ a: [ x ] }: any) { x }
try {} catch ([{ x }]: any) { x }
try {} catch ([[ x ]]: any) { x }
try {} catch ({ a: { b: { c: { x }} }}: any) { x }
try {} catch ({ x }: unknown) { x }
try {} catch ([ x ]: unknown) { x }
try {} catch ({ a: { x } }: unknown) { x }
try {} catch ({ a: [ x ] }: unknown) { x }
try {} catch ([{ x }]: unknown) { x }
try {} catch ([[ x ]]: unknown) { x }
try {} catch ({ a: { b: { c: { x }} }}: unknown) { x }
//// [destructureCatchClause.js]
"use strict";
// These are okay with useUnknownInCatchVariables=false, but not okay with useUnknownInCatchVariables=true.
try { }
catch (_a) {
var x = _a.x;
x;
}
try { }
catch (_b) {
var x = _b[0];
x;
}
try { }
catch (_c) {
var x = _c.a.x;
x;
}
try { }
catch (_d) {
var x = _d.a[0];
x;
}
try { }
catch (_e) {
var x = _e[0].x;
x;
}
try { }
catch (_f) {
var x = _f[0][0];
x;
}
try { }
catch (_g) {
var x = _g.a.b.c.x;
x;
}
try { }
catch (_h) {
var x = _h.x;
x;
}
try { }
catch (_j) {
var x = _j[0];
x;
}
try { }
catch (_k) {
var x = _k.a.x;
x;
}
try { }
catch (_l) {
var x = _l.a[0];
x;
}
try { }
catch (_m) {
var x = _m[0].x;
x;
}
try { }
catch (_o) {
var x = _o[0][0];
x;
}
try { }
catch (_p) {
var x = _p.a.b.c.x;
x;
}
try { }
catch (_q) {
var x = _q.x;
x;
}
try { }
catch (_r) {
var x = _r[0];
x;
}
try { }
catch (_s) {
var x = _s.a.x;
x;
}
try { }
catch (_t) {
var x = _t.a[0];
x;
}
try { }
catch (_u) {
var x = _u[0].x;
x;
}
try { }
catch (_v) {
var x = _v[0][0];
x;
}
try { }
catch (_w) {
var x = _w.a.b.c.x;
x;
}

Просмотреть файл

@ -0,0 +1,88 @@
=== tests/cases/compiler/destructureCatchClause.ts ===
// These are okay with useUnknownInCatchVariables=false, but not okay with useUnknownInCatchVariables=true.
try {} catch ({ x }) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 1, 15))
>x : Symbol(x, Decl(destructureCatchClause.ts, 1, 15))
try {} catch ([ x ]) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 2, 15))
>x : Symbol(x, Decl(destructureCatchClause.ts, 2, 15))
try {} catch ({ a: { x } }) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 4, 20))
>x : Symbol(x, Decl(destructureCatchClause.ts, 4, 20))
try {} catch ({ a: [ x ] }) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 5, 20))
>x : Symbol(x, Decl(destructureCatchClause.ts, 5, 20))
try {} catch ([{ x }]) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 7, 16))
>x : Symbol(x, Decl(destructureCatchClause.ts, 7, 16))
try {} catch ([[ x ]]) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 8, 16))
>x : Symbol(x, Decl(destructureCatchClause.ts, 8, 16))
try {} catch ({ a: { b: { c: { x }} }}) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 10, 30))
>x : Symbol(x, Decl(destructureCatchClause.ts, 10, 30))
try {} catch ({ x }: any) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 13, 15))
>x : Symbol(x, Decl(destructureCatchClause.ts, 13, 15))
try {} catch ([ x ]: any) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 14, 15))
>x : Symbol(x, Decl(destructureCatchClause.ts, 14, 15))
try {} catch ({ a: { x } }: any) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 16, 20))
>x : Symbol(x, Decl(destructureCatchClause.ts, 16, 20))
try {} catch ({ a: [ x ] }: any) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 17, 20))
>x : Symbol(x, Decl(destructureCatchClause.ts, 17, 20))
try {} catch ([{ x }]: any) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 19, 16))
>x : Symbol(x, Decl(destructureCatchClause.ts, 19, 16))
try {} catch ([[ x ]]: any) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 20, 16))
>x : Symbol(x, Decl(destructureCatchClause.ts, 20, 16))
try {} catch ({ a: { b: { c: { x }} }}: any) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 22, 30))
>x : Symbol(x, Decl(destructureCatchClause.ts, 22, 30))
try {} catch ({ x }: unknown) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 25, 15))
>x : Symbol(x, Decl(destructureCatchClause.ts, 25, 15))
try {} catch ([ x ]: unknown) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 26, 15))
>x : Symbol(x, Decl(destructureCatchClause.ts, 26, 15))
try {} catch ({ a: { x } }: unknown) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 28, 20))
>x : Symbol(x, Decl(destructureCatchClause.ts, 28, 20))
try {} catch ({ a: [ x ] }: unknown) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 29, 20))
>x : Symbol(x, Decl(destructureCatchClause.ts, 29, 20))
try {} catch ([{ x }]: unknown) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 31, 16))
>x : Symbol(x, Decl(destructureCatchClause.ts, 31, 16))
try {} catch ([[ x ]]: unknown) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 32, 16))
>x : Symbol(x, Decl(destructureCatchClause.ts, 32, 16))
try {} catch ({ a: { b: { c: { x }} }}: unknown) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 34, 30))
>x : Symbol(x, Decl(destructureCatchClause.ts, 34, 30))

Просмотреть файл

@ -0,0 +1,103 @@
=== tests/cases/compiler/destructureCatchClause.ts ===
// These are okay with useUnknownInCatchVariables=false, but not okay with useUnknownInCatchVariables=true.
try {} catch ({ x }) { x }
>x : any
>x : any
try {} catch ([ x ]) { x }
>x : any
>x : any
try {} catch ({ a: { x } }) { x }
>a : any
>x : any
>x : any
try {} catch ({ a: [ x ] }) { x }
>a : any
>x : any
>x : any
try {} catch ([{ x }]) { x }
>x : any
>x : any
try {} catch ([[ x ]]) { x }
>x : any
>x : any
try {} catch ({ a: { b: { c: { x }} }}) { x }
>a : any
>b : any
>c : any
>x : any
>x : any
try {} catch ({ x }: any) { x }
>x : any
>x : any
try {} catch ([ x ]: any) { x }
>x : any
>x : any
try {} catch ({ a: { x } }: any) { x }
>a : any
>x : any
>x : any
try {} catch ({ a: [ x ] }: any) { x }
>a : any
>x : any
>x : any
try {} catch ([{ x }]: any) { x }
>x : any
>x : any
try {} catch ([[ x ]]: any) { x }
>x : any
>x : any
try {} catch ({ a: { b: { c: { x }} }}: any) { x }
>a : any
>b : any
>c : any
>x : any
>x : any
try {} catch ({ x }: unknown) { x }
>x : any
>x : any
try {} catch ([ x ]: unknown) { x }
>x : any
>x : any
try {} catch ({ a: { x } }: unknown) { x }
>a : any
>x : any
>x : any
try {} catch ({ a: [ x ] }: unknown) { x }
>a : any
>x : any
>x : any
try {} catch ([{ x }]: unknown) { x }
>x : any
>x : any
try {} catch ([[ x ]]: unknown) { x }
>x : any
>x : any
try {} catch ({ a: { b: { c: { x }} }}: unknown) { x }
>a : any
>b : any
>c : any
>x : any
>x : any

Просмотреть файл

@ -0,0 +1,81 @@
tests/cases/compiler/destructureCatchClause.ts(2,17): error TS2339: Property 'x' does not exist on type 'unknown'.
tests/cases/compiler/destructureCatchClause.ts(3,15): error TS2461: Type 'unknown' is not an array type.
tests/cases/compiler/destructureCatchClause.ts(5,17): error TS2339: Property 'a' does not exist on type 'unknown'.
tests/cases/compiler/destructureCatchClause.ts(6,17): error TS2339: Property 'a' does not exist on type 'unknown'.
tests/cases/compiler/destructureCatchClause.ts(8,15): error TS2461: Type 'unknown' is not an array type.
tests/cases/compiler/destructureCatchClause.ts(9,15): error TS2461: Type 'unknown' is not an array type.
tests/cases/compiler/destructureCatchClause.ts(11,17): error TS2339: Property 'a' does not exist on type 'unknown'.
tests/cases/compiler/destructureCatchClause.ts(26,17): error TS2339: Property 'x' does not exist on type 'unknown'.
tests/cases/compiler/destructureCatchClause.ts(27,15): error TS2461: Type 'unknown' is not an array type.
tests/cases/compiler/destructureCatchClause.ts(29,17): error TS2339: Property 'a' does not exist on type 'unknown'.
tests/cases/compiler/destructureCatchClause.ts(30,17): error TS2339: Property 'a' does not exist on type 'unknown'.
tests/cases/compiler/destructureCatchClause.ts(32,15): error TS2461: Type 'unknown' is not an array type.
tests/cases/compiler/destructureCatchClause.ts(33,15): error TS2461: Type 'unknown' is not an array type.
tests/cases/compiler/destructureCatchClause.ts(35,17): error TS2339: Property 'a' does not exist on type 'unknown'.
==== tests/cases/compiler/destructureCatchClause.ts (14 errors) ====
// These are okay with useUnknownInCatchVariables=false, but not okay with useUnknownInCatchVariables=true.
try {} catch ({ x }) { x }
~
!!! error TS2339: Property 'x' does not exist on type 'unknown'.
try {} catch ([ x ]) { x }
~~~~~
!!! error TS2461: Type 'unknown' is not an array type.
try {} catch ({ a: { x } }) { x }
~
!!! error TS2339: Property 'a' does not exist on type 'unknown'.
try {} catch ({ a: [ x ] }) { x }
~
!!! error TS2339: Property 'a' does not exist on type 'unknown'.
try {} catch ([{ x }]) { x }
~~~~~~~
!!! error TS2461: Type 'unknown' is not an array type.
try {} catch ([[ x ]]) { x }
~~~~~~~
!!! error TS2461: Type 'unknown' is not an array type.
try {} catch ({ a: { b: { c: { x }} }}) { x }
~
!!! error TS2339: Property 'a' does not exist on type 'unknown'.
try {} catch ({ x }: any) { x }
try {} catch ([ x ]: any) { x }
try {} catch ({ a: { x } }: any) { x }
try {} catch ({ a: [ x ] }: any) { x }
try {} catch ([{ x }]: any) { x }
try {} catch ([[ x ]]: any) { x }
try {} catch ({ a: { b: { c: { x }} }}: any) { x }
try {} catch ({ x }: unknown) { x }
~
!!! error TS2339: Property 'x' does not exist on type 'unknown'.
try {} catch ([ x ]: unknown) { x }
~~~~~
!!! error TS2461: Type 'unknown' is not an array type.
try {} catch ({ a: { x } }: unknown) { x }
~
!!! error TS2339: Property 'a' does not exist on type 'unknown'.
try {} catch ({ a: [ x ] }: unknown) { x }
~
!!! error TS2339: Property 'a' does not exist on type 'unknown'.
try {} catch ([{ x }]: unknown) { x }
~~~~~~~
!!! error TS2461: Type 'unknown' is not an array type.
try {} catch ([[ x ]]: unknown) { x }
~~~~~~~
!!! error TS2461: Type 'unknown' is not an array type.
try {} catch ({ a: { b: { c: { x }} }}: unknown) { x }
~
!!! error TS2339: Property 'a' does not exist on type 'unknown'.

Просмотреть файл

@ -0,0 +1,146 @@
//// [destructureCatchClause.ts]
// These are okay with useUnknownInCatchVariables=false, but not okay with useUnknownInCatchVariables=true.
try {} catch ({ x }) { x }
try {} catch ([ x ]) { x }
try {} catch ({ a: { x } }) { x }
try {} catch ({ a: [ x ] }) { x }
try {} catch ([{ x }]) { x }
try {} catch ([[ x ]]) { x }
try {} catch ({ a: { b: { c: { x }} }}) { x }
try {} catch ({ x }: any) { x }
try {} catch ([ x ]: any) { x }
try {} catch ({ a: { x } }: any) { x }
try {} catch ({ a: [ x ] }: any) { x }
try {} catch ([{ x }]: any) { x }
try {} catch ([[ x ]]: any) { x }
try {} catch ({ a: { b: { c: { x }} }}: any) { x }
try {} catch ({ x }: unknown) { x }
try {} catch ([ x ]: unknown) { x }
try {} catch ({ a: { x } }: unknown) { x }
try {} catch ({ a: [ x ] }: unknown) { x }
try {} catch ([{ x }]: unknown) { x }
try {} catch ([[ x ]]: unknown) { x }
try {} catch ({ a: { b: { c: { x }} }}: unknown) { x }
//// [destructureCatchClause.js]
"use strict";
// These are okay with useUnknownInCatchVariables=false, but not okay with useUnknownInCatchVariables=true.
try { }
catch (_a) {
var x = _a.x;
x;
}
try { }
catch (_b) {
var x = _b[0];
x;
}
try { }
catch (_c) {
var x = _c.a.x;
x;
}
try { }
catch (_d) {
var x = _d.a[0];
x;
}
try { }
catch (_e) {
var x = _e[0].x;
x;
}
try { }
catch (_f) {
var x = _f[0][0];
x;
}
try { }
catch (_g) {
var x = _g.a.b.c.x;
x;
}
try { }
catch (_h) {
var x = _h.x;
x;
}
try { }
catch (_j) {
var x = _j[0];
x;
}
try { }
catch (_k) {
var x = _k.a.x;
x;
}
try { }
catch (_l) {
var x = _l.a[0];
x;
}
try { }
catch (_m) {
var x = _m[0].x;
x;
}
try { }
catch (_o) {
var x = _o[0][0];
x;
}
try { }
catch (_p) {
var x = _p.a.b.c.x;
x;
}
try { }
catch (_q) {
var x = _q.x;
x;
}
try { }
catch (_r) {
var x = _r[0];
x;
}
try { }
catch (_s) {
var x = _s.a.x;
x;
}
try { }
catch (_t) {
var x = _t.a[0];
x;
}
try { }
catch (_u) {
var x = _u[0].x;
x;
}
try { }
catch (_v) {
var x = _v[0][0];
x;
}
try { }
catch (_w) {
var x = _w.a.b.c.x;
x;
}

Просмотреть файл

@ -0,0 +1,88 @@
=== tests/cases/compiler/destructureCatchClause.ts ===
// These are okay with useUnknownInCatchVariables=false, but not okay with useUnknownInCatchVariables=true.
try {} catch ({ x }) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 1, 15))
>x : Symbol(x, Decl(destructureCatchClause.ts, 1, 15))
try {} catch ([ x ]) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 2, 15))
>x : Symbol(x, Decl(destructureCatchClause.ts, 2, 15))
try {} catch ({ a: { x } }) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 4, 20))
>x : Symbol(x, Decl(destructureCatchClause.ts, 4, 20))
try {} catch ({ a: [ x ] }) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 5, 20))
>x : Symbol(x, Decl(destructureCatchClause.ts, 5, 20))
try {} catch ([{ x }]) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 7, 16))
>x : Symbol(x, Decl(destructureCatchClause.ts, 7, 16))
try {} catch ([[ x ]]) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 8, 16))
>x : Symbol(x, Decl(destructureCatchClause.ts, 8, 16))
try {} catch ({ a: { b: { c: { x }} }}) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 10, 30))
>x : Symbol(x, Decl(destructureCatchClause.ts, 10, 30))
try {} catch ({ x }: any) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 13, 15))
>x : Symbol(x, Decl(destructureCatchClause.ts, 13, 15))
try {} catch ([ x ]: any) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 14, 15))
>x : Symbol(x, Decl(destructureCatchClause.ts, 14, 15))
try {} catch ({ a: { x } }: any) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 16, 20))
>x : Symbol(x, Decl(destructureCatchClause.ts, 16, 20))
try {} catch ({ a: [ x ] }: any) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 17, 20))
>x : Symbol(x, Decl(destructureCatchClause.ts, 17, 20))
try {} catch ([{ x }]: any) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 19, 16))
>x : Symbol(x, Decl(destructureCatchClause.ts, 19, 16))
try {} catch ([[ x ]]: any) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 20, 16))
>x : Symbol(x, Decl(destructureCatchClause.ts, 20, 16))
try {} catch ({ a: { b: { c: { x }} }}: any) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 22, 30))
>x : Symbol(x, Decl(destructureCatchClause.ts, 22, 30))
try {} catch ({ x }: unknown) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 25, 15))
>x : Symbol(x, Decl(destructureCatchClause.ts, 25, 15))
try {} catch ([ x ]: unknown) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 26, 15))
>x : Symbol(x, Decl(destructureCatchClause.ts, 26, 15))
try {} catch ({ a: { x } }: unknown) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 28, 20))
>x : Symbol(x, Decl(destructureCatchClause.ts, 28, 20))
try {} catch ({ a: [ x ] }: unknown) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 29, 20))
>x : Symbol(x, Decl(destructureCatchClause.ts, 29, 20))
try {} catch ([{ x }]: unknown) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 31, 16))
>x : Symbol(x, Decl(destructureCatchClause.ts, 31, 16))
try {} catch ([[ x ]]: unknown) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 32, 16))
>x : Symbol(x, Decl(destructureCatchClause.ts, 32, 16))
try {} catch ({ a: { b: { c: { x }} }}: unknown) { x }
>x : Symbol(x, Decl(destructureCatchClause.ts, 34, 30))
>x : Symbol(x, Decl(destructureCatchClause.ts, 34, 30))

Просмотреть файл

@ -0,0 +1,103 @@
=== tests/cases/compiler/destructureCatchClause.ts ===
// These are okay with useUnknownInCatchVariables=false, but not okay with useUnknownInCatchVariables=true.
try {} catch ({ x }) { x }
>x : any
>x : any
try {} catch ([ x ]) { x }
>x : any
>x : any
try {} catch ({ a: { x } }) { x }
>a : any
>x : any
>x : any
try {} catch ({ a: [ x ] }) { x }
>a : any
>x : any
>x : any
try {} catch ([{ x }]) { x }
>x : any
>x : any
try {} catch ([[ x ]]) { x }
>x : any
>x : any
try {} catch ({ a: { b: { c: { x }} }}) { x }
>a : any
>b : any
>c : any
>x : any
>x : any
try {} catch ({ x }: any) { x }
>x : any
>x : any
try {} catch ([ x ]: any) { x }
>x : any
>x : any
try {} catch ({ a: { x } }: any) { x }
>a : any
>x : any
>x : any
try {} catch ({ a: [ x ] }: any) { x }
>a : any
>x : any
>x : any
try {} catch ([{ x }]: any) { x }
>x : any
>x : any
try {} catch ([[ x ]]: any) { x }
>x : any
>x : any
try {} catch ({ a: { b: { c: { x }} }}: any) { x }
>a : any
>b : any
>c : any
>x : any
>x : any
try {} catch ({ x }: unknown) { x }
>x : any
>x : any
try {} catch ([ x ]: unknown) { x }
>x : any
>x : any
try {} catch ({ a: { x } }: unknown) { x }
>a : any
>x : any
>x : any
try {} catch ({ a: [ x ] }: unknown) { x }
>a : any
>x : any
>x : any
try {} catch ([{ x }]: unknown) { x }
>x : any
>x : any
try {} catch ([[ x ]]: unknown) { x }
>x : any
>x : any
try {} catch ({ a: { b: { c: { x }} }}: unknown) { x }
>a : any
>b : any
>c : any
>x : any
>x : any

Просмотреть файл

@ -31,7 +31,6 @@ try {
>z : Symbol(z, Decl(destructuringCatch.ts, 15, 20))
}
catch ([{x: [y], z}]) {
>x : Symbol(x)
>y : Symbol(y, Decl(destructuringCatch.ts, 17, 13))
>z : Symbol(z, Decl(destructuringCatch.ts, 17, 16))

Просмотреть файл

@ -3,11 +3,13 @@ tests/cases/conformance/jsdoc/foo.js(21,54): error TS2339: Property 'foo' does n
tests/cases/conformance/jsdoc/foo.js(22,31): error TS1196: Catch clause variable type annotation must be 'any' or 'unknown' if specified.
tests/cases/conformance/jsdoc/foo.js(23,31): error TS1196: Catch clause variable type annotation must be 'any' or 'unknown' if specified.
tests/cases/conformance/jsdoc/foo.js(35,7): error TS2492: Cannot redeclare identifier 'err' in catch clause.
tests/cases/conformance/jsdoc/foo.js(46,45): error TS2339: Property 'x' does not exist on type '{}'.
tests/cases/conformance/jsdoc/foo.js(47,45): error TS2339: Property 'x' does not exist on type '{}'.
tests/cases/conformance/jsdoc/foo.js(48,31): error TS1196: Catch clause variable type annotation must be 'any' or 'unknown' if specified.
tests/cases/conformance/jsdoc/foo.js(49,31): error TS1196: Catch clause variable type annotation must be 'any' or 'unknown' if specified.
==== tests/cases/conformance/jsdoc/foo.js (7 errors) ====
==== tests/cases/conformance/jsdoc/foo.js (9 errors) ====
/**
* @typedef {any} Any
*/
@ -63,8 +65,12 @@ tests/cases/conformance/jsdoc/foo.js(49,31): error TS1196: Catch clause variable
try { } catch ({ x }) { } // should be OK
try { } catch (/** @type {any} */ { x }) { x.foo; } // should be OK
try { } catch (/** @type {Any} */ { x }) { x.foo;} // should be OK
try { } catch (/** @type {unknown} */ { x }) { console.log(x); } // should be OK
try { } catch (/** @type {Unknown} */ { x }) { console.log(x); } // should be OK
try { } catch (/** @type {unknown} */ { x }) { console.log(x); } // error in the destructure
~
!!! error TS2339: Property 'x' does not exist on type '{}'.
try { } catch (/** @type {Unknown} */ { x }) { console.log(x); } // error in the destructure
~
!!! error TS2339: Property 'x' does not exist on type '{}'.
try { } catch (/** @type {Error} */ { x }) { } // error in the type
~~~~~
!!! error TS1196: Catch clause variable type annotation must be 'any' or 'unknown' if specified.

Просмотреть файл

@ -44,8 +44,8 @@ function fn() {
try { } catch ({ x }) { } // should be OK
try { } catch (/** @type {any} */ { x }) { x.foo; } // should be OK
try { } catch (/** @type {Any} */ { x }) { x.foo;} // should be OK
try { } catch (/** @type {unknown} */ { x }) { console.log(x); } // should be OK
try { } catch (/** @type {Unknown} */ { x }) { console.log(x); } // should be OK
try { } catch (/** @type {unknown} */ { x }) { console.log(x); } // error in the destructure
try { } catch (/** @type {Unknown} */ { x }) { console.log(x); } // error in the destructure
try { } catch (/** @type {Error} */ { x }) { } // error in the type
try { } catch (/** @type {object} */ { x }) { } // error in the type
}
@ -132,11 +132,11 @@ function fn() {
try { }
catch ( /** @type {unknown} */{ x }) {
console.log(x);
} // should be OK
} // error in the destructure
try { }
catch ( /** @type {Unknown} */{ x }) {
console.log(x);
} // should be OK
} // error in the destructure
try { }
catch ( /** @type {Error} */{ x }) { } // error in the type
try { }

Просмотреть файл

@ -110,14 +110,14 @@ function fn() {
>x : Symbol(x, Decl(foo.js, 44, 39))
>x : Symbol(x, Decl(foo.js, 44, 39))
try { } catch (/** @type {unknown} */ { x }) { console.log(x); } // should be OK
try { } catch (/** @type {unknown} */ { x }) { console.log(x); } // error in the destructure
>x : Symbol(x, Decl(foo.js, 45, 43))
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>x : Symbol(x, Decl(foo.js, 45, 43))
try { } catch (/** @type {Unknown} */ { x }) { console.log(x); } // should be OK
try { } catch (/** @type {Unknown} */ { x }) { console.log(x); } // error in the destructure
>x : Symbol(x, Decl(foo.js, 46, 43))
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))

Просмотреть файл

@ -131,7 +131,7 @@ function fn() {
>x : any
>foo : any
try { } catch (/** @type {unknown} */ { x }) { console.log(x); } // should be OK
try { } catch (/** @type {unknown} */ { x }) { console.log(x); } // error in the destructure
>x : any
>console.log(x) : void
>console.log : (...data: any[]) => void
@ -139,7 +139,7 @@ function fn() {
>log : (...data: any[]) => void
>x : any
try { } catch (/** @type {Unknown} */ { x }) { console.log(x); } // should be OK
try { } catch (/** @type {Unknown} */ { x }) { console.log(x); } // error in the destructure
>x : any
>console.log(x) : void
>console.log : (...data: any[]) => void

Просмотреть файл

@ -31,9 +31,7 @@ try {
try {
} catch ({ a: x, b: x }) {
>a : Symbol(a)
>x : Symbol(x, Decl(redeclareParameterInCatchBlock.ts, 20, 10))
>b : Symbol(b)
>x : Symbol(x, Decl(redeclareParameterInCatchBlock.ts, 20, 16))
}

Просмотреть файл

@ -0,0 +1,38 @@
// @strict: true, false
// @useUnknownInCatchVariables: true, false
// These are okay with useUnknownInCatchVariables=false, but not okay with useUnknownInCatchVariables=true.
try {} catch ({ x }) { x }
try {} catch ([ x ]) { x }
try {} catch ({ a: { x } }) { x }
try {} catch ({ a: [ x ] }) { x }
try {} catch ([{ x }]) { x }
try {} catch ([[ x ]]) { x }
try {} catch ({ a: { b: { c: { x }} }}) { x }
try {} catch ({ x }: any) { x }
try {} catch ([ x ]: any) { x }
try {} catch ({ a: { x } }: any) { x }
try {} catch ({ a: [ x ] }: any) { x }
try {} catch ([{ x }]: any) { x }
try {} catch ([[ x ]]: any) { x }
try {} catch ({ a: { b: { c: { x }} }}: any) { x }
try {} catch ({ x }: unknown) { x }
try {} catch ([ x ]: unknown) { x }
try {} catch ({ a: { x } }: unknown) { x }
try {} catch ({ a: [ x ] }: unknown) { x }
try {} catch ([{ x }]: unknown) { x }
try {} catch ([[ x ]]: unknown) { x }
try {} catch ({ a: { b: { c: { x }} }}: unknown) { x }

Просмотреть файл

@ -50,8 +50,8 @@ function fn() {
try { } catch ({ x }) { } // should be OK
try { } catch (/** @type {any} */ { x }) { x.foo; } // should be OK
try { } catch (/** @type {Any} */ { x }) { x.foo;} // should be OK
try { } catch (/** @type {unknown} */ { x }) { console.log(x); } // should be OK
try { } catch (/** @type {Unknown} */ { x }) { console.log(x); } // should be OK
try { } catch (/** @type {unknown} */ { x }) { console.log(x); } // error in the destructure
try { } catch (/** @type {Unknown} */ { x }) { console.log(x); } // error in the destructure
try { } catch (/** @type {Error} */ { x }) { } // error in the type
try { } catch (/** @type {object} */ { x }) { } // error in the type
}

Просмотреть файл

@ -33,8 +33,8 @@ function fn(x: boolean) {
try { } catch ({ x }) { } // should be OK
try { } catch ({ x }: any) { x.foo; } // should be OK
try { } catch ({ x }: any1) { x.foo;} // should be OK
try { } catch ({ x }: unknown) { console.log(x); } // should be OK
try { } catch ({ x }: unknown1) { console.log(x); } // should be OK
try { } catch ({ x }: unknown) { console.log(x); } // error in the destructure
try { } catch ({ x }: unknown1) { console.log(x); } // error in the destructure
try { } catch ({ x }: object) { } // error in the type
try { } catch ({ x }: Error) { } // error in the type
}