From f279dd5edccc6c93b8f6996e7c71da5a37f440e9 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Wed, 31 Aug 2022 10:29:09 +0300 Subject: [PATCH 1/3] fix(50551): handle destructuring variables used before assignment --- src/compiler/checker.ts | 2 +- ...estructuringVariablesInTryCatch.errors.txt | 28 ++++++++++++ ...rolFlowDestructuringVariablesInTryCatch.js | 31 +++++++++++++ ...owDestructuringVariablesInTryCatch.symbols | 40 +++++++++++++++++ ...FlowDestructuringVariablesInTryCatch.types | 45 +++++++++++++++++++ ...rolFlowDestructuringVariablesInTryCatch.ts | 17 +++++++ 6 files changed, 162 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/controlFlowDestructuringVariablesInTryCatch.errors.txt create mode 100644 tests/baselines/reference/controlFlowDestructuringVariablesInTryCatch.js create mode 100644 tests/baselines/reference/controlFlowDestructuringVariablesInTryCatch.symbols create mode 100644 tests/baselines/reference/controlFlowDestructuringVariablesInTryCatch.types create mode 100644 tests/cases/compiler/controlFlowDestructuringVariablesInTryCatch.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e911d7fe7d2a3..d2aeb57054f54 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -26095,7 +26095,7 @@ namespace ts { // 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 || isBindingElement(declaration) || + const assumeInitialized = isParameter || isAlias || isOuterVariable || isSpreadDestructuringAssignmentTarget || isModuleExports || type !== autoType && type !== autoArrayType && (!strictNullChecks || (type.flags & (TypeFlags.AnyOrUnknown | TypeFlags.Void)) !== 0 || isInTypeQuery(node) || node.parent.kind === SyntaxKind.ExportSpecifier) || node.parent.kind === SyntaxKind.NonNullExpression || diff --git a/tests/baselines/reference/controlFlowDestructuringVariablesInTryCatch.errors.txt b/tests/baselines/reference/controlFlowDestructuringVariablesInTryCatch.errors.txt new file mode 100644 index 0000000000000..539f8e42b85c1 --- /dev/null +++ b/tests/baselines/reference/controlFlowDestructuringVariablesInTryCatch.errors.txt @@ -0,0 +1,28 @@ +tests/cases/compiler/controlFlowDestructuringVariablesInTryCatch.ts(13,1): error TS2454: Variable 'a' is used before being assigned. +tests/cases/compiler/controlFlowDestructuringVariablesInTryCatch.ts(14,1): error TS2454: Variable 'b' is used before being assigned. +tests/cases/compiler/controlFlowDestructuringVariablesInTryCatch.ts(15,1): error TS2454: Variable 'c' is used before being assigned. + + +==== tests/cases/compiler/controlFlowDestructuringVariablesInTryCatch.ts (3 errors) ==== + declare function f1(): string; + declare function f2(): [b: string]; + declare function f3(): { c: string }; + + try { + var a = f1(); + var [b] = f2(); + var { c } = f3(); + } catch { + console.error("error"); + } + + a; + ~ +!!! error TS2454: Variable 'a' is used before being assigned. + b; + ~ +!!! error TS2454: Variable 'b' is used before being assigned. + c; + ~ +!!! error TS2454: Variable 'c' is used before being assigned. + \ No newline at end of file diff --git a/tests/baselines/reference/controlFlowDestructuringVariablesInTryCatch.js b/tests/baselines/reference/controlFlowDestructuringVariablesInTryCatch.js new file mode 100644 index 0000000000000..c2a05c01d173f --- /dev/null +++ b/tests/baselines/reference/controlFlowDestructuringVariablesInTryCatch.js @@ -0,0 +1,31 @@ +//// [controlFlowDestructuringVariablesInTryCatch.ts] +declare function f1(): string; +declare function f2(): [b: string]; +declare function f3(): { c: string }; + +try { + var a = f1(); + var [b] = f2(); + var { c } = f3(); +} catch { + console.error("error"); +} + +a; +b; +c; + + +//// [controlFlowDestructuringVariablesInTryCatch.js] +"use strict"; +try { + var a = f1(); + var b = f2()[0]; + var c = f3().c; +} +catch (_a) { + console.error("error"); +} +a; +b; +c; diff --git a/tests/baselines/reference/controlFlowDestructuringVariablesInTryCatch.symbols b/tests/baselines/reference/controlFlowDestructuringVariablesInTryCatch.symbols new file mode 100644 index 0000000000000..e1aca6859a500 --- /dev/null +++ b/tests/baselines/reference/controlFlowDestructuringVariablesInTryCatch.symbols @@ -0,0 +1,40 @@ +=== tests/cases/compiler/controlFlowDestructuringVariablesInTryCatch.ts === +declare function f1(): string; +>f1 : Symbol(f1, Decl(controlFlowDestructuringVariablesInTryCatch.ts, 0, 0)) + +declare function f2(): [b: string]; +>f2 : Symbol(f2, Decl(controlFlowDestructuringVariablesInTryCatch.ts, 0, 30)) + +declare function f3(): { c: string }; +>f3 : Symbol(f3, Decl(controlFlowDestructuringVariablesInTryCatch.ts, 1, 35)) +>c : Symbol(c, Decl(controlFlowDestructuringVariablesInTryCatch.ts, 2, 24)) + +try { + var a = f1(); +>a : Symbol(a, Decl(controlFlowDestructuringVariablesInTryCatch.ts, 5, 7)) +>f1 : Symbol(f1, Decl(controlFlowDestructuringVariablesInTryCatch.ts, 0, 0)) + + var [b] = f2(); +>b : Symbol(b, Decl(controlFlowDestructuringVariablesInTryCatch.ts, 6, 9)) +>f2 : Symbol(f2, Decl(controlFlowDestructuringVariablesInTryCatch.ts, 0, 30)) + + var { c } = f3(); +>c : Symbol(c, Decl(controlFlowDestructuringVariablesInTryCatch.ts, 7, 9)) +>f3 : Symbol(f3, Decl(controlFlowDestructuringVariablesInTryCatch.ts, 1, 35)) + +} catch { + console.error("error"); +>console.error : Symbol(Console.error, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>error : Symbol(Console.error, Decl(lib.dom.d.ts, --, --)) +} + +a; +>a : Symbol(a, Decl(controlFlowDestructuringVariablesInTryCatch.ts, 5, 7)) + +b; +>b : Symbol(b, Decl(controlFlowDestructuringVariablesInTryCatch.ts, 6, 9)) + +c; +>c : Symbol(c, Decl(controlFlowDestructuringVariablesInTryCatch.ts, 7, 9)) + diff --git a/tests/baselines/reference/controlFlowDestructuringVariablesInTryCatch.types b/tests/baselines/reference/controlFlowDestructuringVariablesInTryCatch.types new file mode 100644 index 0000000000000..0928252431370 --- /dev/null +++ b/tests/baselines/reference/controlFlowDestructuringVariablesInTryCatch.types @@ -0,0 +1,45 @@ +=== tests/cases/compiler/controlFlowDestructuringVariablesInTryCatch.ts === +declare function f1(): string; +>f1 : () => string + +declare function f2(): [b: string]; +>f2 : () => [b: string] + +declare function f3(): { c: string }; +>f3 : () => { c: string; } +>c : string + +try { + var a = f1(); +>a : string +>f1() : string +>f1 : () => string + + var [b] = f2(); +>b : string +>f2() : [b: string] +>f2 : () => [b: string] + + var { c } = f3(); +>c : string +>f3() : { c: string; } +>f3 : () => { c: string; } + +} catch { + console.error("error"); +>console.error("error") : void +>console.error : (...data: any[]) => void +>console : Console +>error : (...data: any[]) => void +>"error" : "error" +} + +a; +>a : string + +b; +>b : string + +c; +>c : string + diff --git a/tests/cases/compiler/controlFlowDestructuringVariablesInTryCatch.ts b/tests/cases/compiler/controlFlowDestructuringVariablesInTryCatch.ts new file mode 100644 index 0000000000000..c58ab2f14554d --- /dev/null +++ b/tests/cases/compiler/controlFlowDestructuringVariablesInTryCatch.ts @@ -0,0 +1,17 @@ +// @strict: true + +declare function f1(): string; +declare function f2(): [b: string]; +declare function f3(): { c: string }; + +try { + var a = f1(); + var [b] = f2(); + var { c } = f3(); +} catch { + console.error("error"); +} + +a; +b; +c; From a6e5486a25f50d501385d6f3a11bacf53de748ba Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Wed, 31 Aug 2022 13:14:57 +0300 Subject: [PATCH 2/3] skip the error in binding elements that refer to the same destructuring --- src/compiler/checker.ts | 2 +- ...estructuringVariablesInTryCatch.errors.txt | 19 +++++++++++++++---- ...rolFlowDestructuringVariablesInTryCatch.js | 11 ++++++++++- ...owDestructuringVariablesInTryCatch.symbols | 12 ++++++++++++ ...FlowDestructuringVariablesInTryCatch.types | 16 ++++++++++++++++ ...itializedDestructuringVariables.errors.txt | 12 ++++++++++++ ...olFlowInitializedDestructuringVariables.js | 11 +++++++++++ ...wInitializedDestructuringVariables.symbols | 17 +++++++++++++++++ ...lowInitializedDestructuringVariables.types | 19 +++++++++++++++++++ ...rolFlowDestructuringVariablesInTryCatch.ts | 5 +++++ ...olFlowInitializedDestructuringVariables.ts | 7 +++++++ 11 files changed, 125 insertions(+), 6 deletions(-) create mode 100644 tests/baselines/reference/controlFlowInitializedDestructuringVariables.errors.txt create mode 100644 tests/baselines/reference/controlFlowInitializedDestructuringVariables.js create mode 100644 tests/baselines/reference/controlFlowInitializedDestructuringVariables.symbols create mode 100644 tests/baselines/reference/controlFlowInitializedDestructuringVariables.types create mode 100644 tests/cases/compiler/controlFlowInitializedDestructuringVariables.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d2aeb57054f54..a9a579216d64e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -26117,7 +26117,7 @@ namespace ts { return convertAutoToAny(flowType); } } - else if (!assumeInitialized && !containsUndefinedType(type) && containsUndefinedType(flowType)) { + else if (!assumeInitialized && !containsUndefinedType(type) && containsUndefinedType(flowType) && !(isBindingElement(declaration) && findAncestor(node, isBindingElement))) { error(node, Diagnostics.Variable_0_is_used_before_being_assigned, symbolToString(symbol)); // Return the declared type to reduce follow-on errors return type; diff --git a/tests/baselines/reference/controlFlowDestructuringVariablesInTryCatch.errors.txt b/tests/baselines/reference/controlFlowDestructuringVariablesInTryCatch.errors.txt index 539f8e42b85c1..dbc664da588da 100644 --- a/tests/baselines/reference/controlFlowDestructuringVariablesInTryCatch.errors.txt +++ b/tests/baselines/reference/controlFlowDestructuringVariablesInTryCatch.errors.txt @@ -1,9 +1,11 @@ -tests/cases/compiler/controlFlowDestructuringVariablesInTryCatch.ts(13,1): error TS2454: Variable 'a' is used before being assigned. -tests/cases/compiler/controlFlowDestructuringVariablesInTryCatch.ts(14,1): error TS2454: Variable 'b' is used before being assigned. -tests/cases/compiler/controlFlowDestructuringVariablesInTryCatch.ts(15,1): error TS2454: Variable 'c' is used before being assigned. +tests/cases/compiler/controlFlowDestructuringVariablesInTryCatch.ts(16,1): error TS2454: Variable 'a' is used before being assigned. +tests/cases/compiler/controlFlowDestructuringVariablesInTryCatch.ts(17,1): error TS2454: Variable 'b' is used before being assigned. +tests/cases/compiler/controlFlowDestructuringVariablesInTryCatch.ts(18,1): error TS2454: Variable 'c' is used before being assigned. +tests/cases/compiler/controlFlowDestructuringVariablesInTryCatch.ts(19,1): error TS2454: Variable 'd' is used before being assigned. +tests/cases/compiler/controlFlowDestructuringVariablesInTryCatch.ts(20,1): error TS2454: Variable 'e' is used before being assigned. -==== tests/cases/compiler/controlFlowDestructuringVariablesInTryCatch.ts (3 errors) ==== +==== tests/cases/compiler/controlFlowDestructuringVariablesInTryCatch.ts (5 errors) ==== declare function f1(): string; declare function f2(): [b: string]; declare function f3(): { c: string }; @@ -12,6 +14,9 @@ tests/cases/compiler/controlFlowDestructuringVariablesInTryCatch.ts(15,1): error var a = f1(); var [b] = f2(); var { c } = f3(); + + var [d = 1] = []; + var { e = 1 } = { }; } catch { console.error("error"); } @@ -25,4 +30,10 @@ tests/cases/compiler/controlFlowDestructuringVariablesInTryCatch.ts(15,1): error c; ~ !!! error TS2454: Variable 'c' is used before being assigned. + d; + ~ +!!! error TS2454: Variable 'd' is used before being assigned. + e; + ~ +!!! error TS2454: Variable 'e' is used before being assigned. \ No newline at end of file diff --git a/tests/baselines/reference/controlFlowDestructuringVariablesInTryCatch.js b/tests/baselines/reference/controlFlowDestructuringVariablesInTryCatch.js index c2a05c01d173f..a64aba170d6dd 100644 --- a/tests/baselines/reference/controlFlowDestructuringVariablesInTryCatch.js +++ b/tests/baselines/reference/controlFlowDestructuringVariablesInTryCatch.js @@ -7,6 +7,9 @@ try { var a = f1(); var [b] = f2(); var { c } = f3(); + + var [d = 1] = []; + var { e = 1 } = { }; } catch { console.error("error"); } @@ -14,6 +17,8 @@ try { a; b; c; +d; +e; //// [controlFlowDestructuringVariablesInTryCatch.js] @@ -22,10 +27,14 @@ try { var a = f1(); var b = f2()[0]; var c = f3().c; + var _a = [][0], d = _a === void 0 ? 1 : _a; + var _b = {}.e, e = _b === void 0 ? 1 : _b; } -catch (_a) { +catch (_c) { console.error("error"); } a; b; c; +d; +e; diff --git a/tests/baselines/reference/controlFlowDestructuringVariablesInTryCatch.symbols b/tests/baselines/reference/controlFlowDestructuringVariablesInTryCatch.symbols index e1aca6859a500..c41f27f9ef62f 100644 --- a/tests/baselines/reference/controlFlowDestructuringVariablesInTryCatch.symbols +++ b/tests/baselines/reference/controlFlowDestructuringVariablesInTryCatch.symbols @@ -22,6 +22,12 @@ try { >c : Symbol(c, Decl(controlFlowDestructuringVariablesInTryCatch.ts, 7, 9)) >f3 : Symbol(f3, Decl(controlFlowDestructuringVariablesInTryCatch.ts, 1, 35)) + var [d = 1] = []; +>d : Symbol(d, Decl(controlFlowDestructuringVariablesInTryCatch.ts, 9, 9)) + + var { e = 1 } = { }; +>e : Symbol(e, Decl(controlFlowDestructuringVariablesInTryCatch.ts, 10, 9)) + } catch { console.error("error"); >console.error : Symbol(Console.error, Decl(lib.dom.d.ts, --, --)) @@ -38,3 +44,9 @@ b; c; >c : Symbol(c, Decl(controlFlowDestructuringVariablesInTryCatch.ts, 7, 9)) +d; +>d : Symbol(d, Decl(controlFlowDestructuringVariablesInTryCatch.ts, 9, 9)) + +e; +>e : Symbol(e, Decl(controlFlowDestructuringVariablesInTryCatch.ts, 10, 9)) + diff --git a/tests/baselines/reference/controlFlowDestructuringVariablesInTryCatch.types b/tests/baselines/reference/controlFlowDestructuringVariablesInTryCatch.types index 0928252431370..2cf5b8d5ec372 100644 --- a/tests/baselines/reference/controlFlowDestructuringVariablesInTryCatch.types +++ b/tests/baselines/reference/controlFlowDestructuringVariablesInTryCatch.types @@ -25,6 +25,16 @@ try { >f3() : { c: string; } >f3 : () => { c: string; } + var [d = 1] = []; +>d : number +>1 : 1 +>[] : [] + + var { e = 1 } = { }; +>e : number +>1 : 1 +>{ } : { e?: number | undefined; } + } catch { console.error("error"); >console.error("error") : void @@ -43,3 +53,9 @@ b; c; >c : string +d; +>d : number + +e; +>e : number + diff --git a/tests/baselines/reference/controlFlowInitializedDestructuringVariables.errors.txt b/tests/baselines/reference/controlFlowInitializedDestructuringVariables.errors.txt new file mode 100644 index 0000000000000..9f431e8ecaaee --- /dev/null +++ b/tests/baselines/reference/controlFlowInitializedDestructuringVariables.errors.txt @@ -0,0 +1,12 @@ +tests/cases/compiler/controlFlowInitializedDestructuringVariables.ts(4,10): error TS2532: Object is possibly 'undefined'. + + +==== tests/cases/compiler/controlFlowInitializedDestructuringVariables.ts (1 errors) ==== + declare const obj: { a?: string, b?: number }; + const { + a = "0", + b = +a, + ~ +!!! error TS2532: Object is possibly 'undefined'. + } = obj; + \ No newline at end of file diff --git a/tests/baselines/reference/controlFlowInitializedDestructuringVariables.js b/tests/baselines/reference/controlFlowInitializedDestructuringVariables.js new file mode 100644 index 0000000000000..843b6939b2562 --- /dev/null +++ b/tests/baselines/reference/controlFlowInitializedDestructuringVariables.js @@ -0,0 +1,11 @@ +//// [controlFlowInitializedDestructuringVariables.ts] +declare const obj: { a?: string, b?: number }; +const { + a = "0", + b = +a, +} = obj; + + +//// [controlFlowInitializedDestructuringVariables.js] +"use strict"; +var _a = obj.a, a = _a === void 0 ? "0" : _a, _b = obj.b, b = _b === void 0 ? +a : _b; diff --git a/tests/baselines/reference/controlFlowInitializedDestructuringVariables.symbols b/tests/baselines/reference/controlFlowInitializedDestructuringVariables.symbols new file mode 100644 index 0000000000000..f664c9db2b9d0 --- /dev/null +++ b/tests/baselines/reference/controlFlowInitializedDestructuringVariables.symbols @@ -0,0 +1,17 @@ +=== tests/cases/compiler/controlFlowInitializedDestructuringVariables.ts === +declare const obj: { a?: string, b?: number }; +>obj : Symbol(obj, Decl(controlFlowInitializedDestructuringVariables.ts, 0, 13)) +>a : Symbol(a, Decl(controlFlowInitializedDestructuringVariables.ts, 0, 20)) +>b : Symbol(b, Decl(controlFlowInitializedDestructuringVariables.ts, 0, 32)) + +const { + a = "0", +>a : Symbol(a, Decl(controlFlowInitializedDestructuringVariables.ts, 1, 7)) + + b = +a, +>b : Symbol(b, Decl(controlFlowInitializedDestructuringVariables.ts, 2, 12)) +>a : Symbol(a, Decl(controlFlowInitializedDestructuringVariables.ts, 1, 7)) + +} = obj; +>obj : Symbol(obj, Decl(controlFlowInitializedDestructuringVariables.ts, 0, 13)) + diff --git a/tests/baselines/reference/controlFlowInitializedDestructuringVariables.types b/tests/baselines/reference/controlFlowInitializedDestructuringVariables.types new file mode 100644 index 0000000000000..9e4807866cafa --- /dev/null +++ b/tests/baselines/reference/controlFlowInitializedDestructuringVariables.types @@ -0,0 +1,19 @@ +=== tests/cases/compiler/controlFlowInitializedDestructuringVariables.ts === +declare const obj: { a?: string, b?: number }; +>obj : { a?: string | undefined; b?: number | undefined; } +>a : string | undefined +>b : number | undefined + +const { + a = "0", +>a : string +>"0" : "0" + + b = +a, +>b : number +>+a : number +>a : string | undefined + +} = obj; +>obj : { a?: string | undefined; b?: number | undefined; } + diff --git a/tests/cases/compiler/controlFlowDestructuringVariablesInTryCatch.ts b/tests/cases/compiler/controlFlowDestructuringVariablesInTryCatch.ts index c58ab2f14554d..a3dd7e4f810db 100644 --- a/tests/cases/compiler/controlFlowDestructuringVariablesInTryCatch.ts +++ b/tests/cases/compiler/controlFlowDestructuringVariablesInTryCatch.ts @@ -8,6 +8,9 @@ try { var a = f1(); var [b] = f2(); var { c } = f3(); + + var [d = 1] = []; + var { e = 1 } = { }; } catch { console.error("error"); } @@ -15,3 +18,5 @@ try { a; b; c; +d; +e; diff --git a/tests/cases/compiler/controlFlowInitializedDestructuringVariables.ts b/tests/cases/compiler/controlFlowInitializedDestructuringVariables.ts new file mode 100644 index 0000000000000..d87dba83a0f42 --- /dev/null +++ b/tests/cases/compiler/controlFlowInitializedDestructuringVariables.ts @@ -0,0 +1,7 @@ +// @strict: true + +declare const obj: { a?: string, b?: number }; +const { + a = "0", + b = +a, +} = obj; From 9d1e9bbcd341b35b0b522edc6ce0021d7c6e7437 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Wed, 19 Oct 2022 19:22:10 +0300 Subject: [PATCH 3/3] fix binding element type --- src/compiler/checker.ts | 11 +++++++++-- ...lFlowInitializedDestructuringVariables.errors.txt | 12 ------------ ...ontrolFlowInitializedDestructuringVariables.types | 2 +- 3 files changed, 10 insertions(+), 15 deletions(-) delete mode 100644 tests/baselines/reference/controlFlowInitializedDestructuringVariables.errors.txt diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a9a579216d64e..9f96aa328de2a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -26095,7 +26095,7 @@ namespace ts { // 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 || + const assumeInitialized = isParameter || isAlias || isOuterVariable || isSpreadDestructuringAssignmentTarget || isModuleExports || isSameScopedBindingElement(node, declaration) || type !== autoType && type !== autoArrayType && (!strictNullChecks || (type.flags & (TypeFlags.AnyOrUnknown | TypeFlags.Void)) !== 0 || isInTypeQuery(node) || node.parent.kind === SyntaxKind.ExportSpecifier) || node.parent.kind === SyntaxKind.NonNullExpression || @@ -26117,7 +26117,7 @@ namespace ts { return convertAutoToAny(flowType); } } - else if (!assumeInitialized && !containsUndefinedType(type) && containsUndefinedType(flowType) && !(isBindingElement(declaration) && findAncestor(node, isBindingElement))) { + else if (!assumeInitialized && !containsUndefinedType(type) && containsUndefinedType(flowType)) { error(node, Diagnostics.Variable_0_is_used_before_being_assigned, symbolToString(symbol)); // Return the declared type to reduce follow-on errors return type; @@ -26125,6 +26125,13 @@ namespace ts { return assignmentKind ? getBaseTypeOfLiteralType(flowType) : flowType; } + function isSameScopedBindingElement(node: Identifier, declaration: Declaration) { + if (isBindingElement(declaration)) { + const bindingElement = findAncestor(node, isBindingElement); + return bindingElement && getRootDeclaration(bindingElement) === getRootDeclaration(declaration); + } + } + function shouldMarkIdentifierAliasReferenced(node: Identifier): boolean { const parent = node.parent; if (parent) { diff --git a/tests/baselines/reference/controlFlowInitializedDestructuringVariables.errors.txt b/tests/baselines/reference/controlFlowInitializedDestructuringVariables.errors.txt deleted file mode 100644 index 9f431e8ecaaee..0000000000000 --- a/tests/baselines/reference/controlFlowInitializedDestructuringVariables.errors.txt +++ /dev/null @@ -1,12 +0,0 @@ -tests/cases/compiler/controlFlowInitializedDestructuringVariables.ts(4,10): error TS2532: Object is possibly 'undefined'. - - -==== tests/cases/compiler/controlFlowInitializedDestructuringVariables.ts (1 errors) ==== - declare const obj: { a?: string, b?: number }; - const { - a = "0", - b = +a, - ~ -!!! error TS2532: Object is possibly 'undefined'. - } = obj; - \ No newline at end of file diff --git a/tests/baselines/reference/controlFlowInitializedDestructuringVariables.types b/tests/baselines/reference/controlFlowInitializedDestructuringVariables.types index 9e4807866cafa..8c64c50a3275c 100644 --- a/tests/baselines/reference/controlFlowInitializedDestructuringVariables.types +++ b/tests/baselines/reference/controlFlowInitializedDestructuringVariables.types @@ -12,7 +12,7 @@ const { b = +a, >b : number >+a : number ->a : string | undefined +>a : string } = obj; >obj : { a?: string | undefined; b?: number | undefined; }