diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 348d6051831a2..922ae9abf702c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -30853,7 +30853,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function getNarrowedTypeOfSymbol(symbol: Symbol, location: Identifier) { const type = getTypeOfSymbol(symbol); const declaration = symbol.valueDeclaration; - if (declaration) { + if (declaration && !textRangeContainsPositionInclusive(getRootDeclaration(declaration), location.pos)) { // If we have a non-rest binding element with no initializer declared as a const variable or a const-like // parameter (a parameter for which there are no assignments in the function body), and if the parent type // for the destructuring is a union type, one or more of the binding elements may represent discriminant @@ -30881,23 +30881,18 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const parent = declaration.parent.parent; const rootDeclaration = getRootDeclaration(parent); if (rootDeclaration.kind === SyntaxKind.VariableDeclaration && getCombinedNodeFlagsCached(rootDeclaration) & NodeFlags.Constant || rootDeclaration.kind === SyntaxKind.Parameter) { - const links = getNodeLinks(parent); - if (!(links.flags & NodeCheckFlags.InCheckIdentifier)) { - links.flags |= NodeCheckFlags.InCheckIdentifier; - const parentType = getTypeForBindingElementParent(parent, CheckMode.Normal); - const parentTypeConstraint = parentType && mapType(parentType, getBaseConstraintOrType); - links.flags &= ~NodeCheckFlags.InCheckIdentifier; - if (parentTypeConstraint && parentTypeConstraint.flags & TypeFlags.Union && !(rootDeclaration.kind === SyntaxKind.Parameter && isSomeSymbolAssigned(rootDeclaration))) { - const pattern = declaration.parent; - const narrowedType = getFlowTypeOfReference(pattern, parentTypeConstraint, parentTypeConstraint, /*flowContainer*/ undefined, location.flowNode); - if (narrowedType.flags & TypeFlags.Never) { - return neverType; - } - // Destructurings are validated against the parent type elsewhere. Here we disable tuple bounds - // checks because the narrowed type may have lower arity than the full parent type. For example, - // for the declaration [x, y]: [1, 2] | [3], we may have narrowed the parent type to just [3]. - return getBindingElementTypeFromParentType(declaration, narrowedType, /*noTupleBoundsCheck*/ true); + const parentType = getTypeForBindingElementParent(parent, CheckMode.Normal); + const parentTypeConstraint = parentType && mapType(parentType, getBaseConstraintOrType); + if (parentTypeConstraint && parentTypeConstraint.flags & TypeFlags.Union && !(rootDeclaration.kind === SyntaxKind.Parameter && isSomeSymbolAssigned(rootDeclaration))) { + const pattern = declaration.parent; + const narrowedType = getFlowTypeOfReference(pattern, parentTypeConstraint, parentTypeConstraint, /*flowContainer*/ undefined, location.flowNode); + if (narrowedType.flags & TypeFlags.Never) { + return neverType; } + // Destructurings are validated against the parent type elsewhere. Here we disable tuple bounds + // checks because the narrowed type may have lower arity than the full parent type. For example, + // for the declaration [x, y]: [1, 2] | [3], we may have narrowed the parent type to just [3]. + return getBindingElementTypeFromParentType(declaration, narrowedType, /*noTupleBoundsCheck*/ true); } } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index df5d03e7ef964..2c2ef1dae8cfc 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -6240,8 +6240,7 @@ export const enum NodeCheckFlags { ConstructorReference = 1 << 29, // Binding to a class constructor inside of the class's body. ContainsClassWithPrivateIdentifiers = 1 << 20, // Marked on all block-scoped containers containing a class with private identifiers. ContainsSuperPropertyInStaticInitializer = 1 << 21, // Marked on all block-scoped containers containing a static initializer with 'super.x' or 'super[x]'. - InCheckIdentifier = 1 << 22, - PartiallyTypeChecked = 1 << 23, // Node has been partially type checked + PartiallyTypeChecked = 1 << 22, // Node has been partially type checked /** These flags are LazyNodeCheckFlags and can be calculated lazily by `hasNodeCheckFlag` */ LazyFlags = SuperInstance diff --git a/tests/baselines/reference/dependentDestructuredVariablesNoCrash1.errors.txt b/tests/baselines/reference/dependentDestructuredVariablesNoCrash1.errors.txt new file mode 100644 index 0000000000000..99aafbaf949ea --- /dev/null +++ b/tests/baselines/reference/dependentDestructuredVariablesNoCrash1.errors.txt @@ -0,0 +1,24 @@ +dependentDestructuredVariablesNoCrash1.ts(3,10): error TS7010: 'f', which lacks return-type annotation, implicitly has an 'any' return type. +dependentDestructuredVariablesNoCrash1.ts(5,12): error TS1015: Parameter cannot have question mark and initializer. +dependentDestructuredVariablesNoCrash1.ts(5,12): error TS2488: Type '(() => any) | undefined' must have a '[Symbol.iterator]()' method that returns an iterator. +dependentDestructuredVariablesNoCrash1.ts(5,20): error TS7022: 'undefined' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. +dependentDestructuredVariablesNoCrash1.ts(5,45): error TS2373: Parameter '[first, undefined]' cannot reference identifier 'undefined' declared after it. + + +==== dependentDestructuredVariablesNoCrash1.ts (5 errors) ==== + // https://github.com/microsoft/TypeScript/issues/63044 + + function f() + ~ +!!! error TS7010: 'f', which lacks return-type annotation, implicitly has an 'any' return type. + + function f([first, undefined]?: () => any = undefined) {} + ~~~~~~~~~~~~~~~~~~ +!!! error TS1015: Parameter cannot have question mark and initializer. + ~~~~~~~~~~~~~~~~~~ +!!! error TS2488: Type '(() => any) | undefined' must have a '[Symbol.iterator]()' method that returns an iterator. + ~~~~~~~~~ +!!! error TS7022: 'undefined' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. + ~~~~~~~~~ +!!! error TS2373: Parameter '[first, undefined]' cannot reference identifier 'undefined' declared after it. + \ No newline at end of file diff --git a/tests/baselines/reference/dependentDestructuredVariablesNoCrash1.js b/tests/baselines/reference/dependentDestructuredVariablesNoCrash1.js new file mode 100644 index 0000000000000..433d124f4e8fa --- /dev/null +++ b/tests/baselines/reference/dependentDestructuredVariablesNoCrash1.js @@ -0,0 +1,18 @@ +//// [tests/cases/conformance/controlFlow/dependentDestructuredVariablesNoCrash1.ts] //// + +//// [dependentDestructuredVariablesNoCrash1.ts] +// https://github.com/microsoft/TypeScript/issues/63044 + +function f() + +function f([first, undefined]?: () => any = undefined) {} + + +//// [dependentDestructuredVariablesNoCrash1.js] +"use strict"; +// https://github.com/microsoft/TypeScript/issues/63044 +function f([first, undefined] = undefined) { } + + +//// [dependentDestructuredVariablesNoCrash1.d.ts] +declare function f(): any; diff --git a/tests/baselines/reference/dependentDestructuredVariablesNoCrash1.symbols b/tests/baselines/reference/dependentDestructuredVariablesNoCrash1.symbols new file mode 100644 index 0000000000000..2dad5e975f307 --- /dev/null +++ b/tests/baselines/reference/dependentDestructuredVariablesNoCrash1.symbols @@ -0,0 +1,14 @@ +//// [tests/cases/conformance/controlFlow/dependentDestructuredVariablesNoCrash1.ts] //// + +=== dependentDestructuredVariablesNoCrash1.ts === +// https://github.com/microsoft/TypeScript/issues/63044 + +function f() +>f : Symbol(f, Decl(dependentDestructuredVariablesNoCrash1.ts, 0, 0), Decl(dependentDestructuredVariablesNoCrash1.ts, 2, 12)) + +function f([first, undefined]?: () => any = undefined) {} +>f : Symbol(f, Decl(dependentDestructuredVariablesNoCrash1.ts, 0, 0), Decl(dependentDestructuredVariablesNoCrash1.ts, 2, 12)) +>first : Symbol(first, Decl(dependentDestructuredVariablesNoCrash1.ts, 4, 12)) +>undefined : Symbol(undefined, Decl(dependentDestructuredVariablesNoCrash1.ts, 4, 18)) +>undefined : Symbol(undefined, Decl(dependentDestructuredVariablesNoCrash1.ts, 4, 18)) + diff --git a/tests/baselines/reference/dependentDestructuredVariablesNoCrash1.types b/tests/baselines/reference/dependentDestructuredVariablesNoCrash1.types new file mode 100644 index 0000000000000..5b5b418356cee --- /dev/null +++ b/tests/baselines/reference/dependentDestructuredVariablesNoCrash1.types @@ -0,0 +1,19 @@ +//// [tests/cases/conformance/controlFlow/dependentDestructuredVariablesNoCrash1.ts] //// + +=== dependentDestructuredVariablesNoCrash1.ts === +// https://github.com/microsoft/TypeScript/issues/63044 + +function f() +>f : () => any +> : ^^^^^^^^^ + +function f([first, undefined]?: () => any = undefined) {} +>f : () => any +> : ^^^^^^^^^ +>first : any +> : ^^^ +>undefined : any +> : ^^^ +>undefined : any +> : ^^^ + diff --git a/tests/baselines/reference/dependentDestructuredVariablesNoCrash2.errors.txt b/tests/baselines/reference/dependentDestructuredVariablesNoCrash2.errors.txt new file mode 100644 index 0000000000000..84f6a68a8bff1 --- /dev/null +++ b/tests/baselines/reference/dependentDestructuredVariablesNoCrash2.errors.txt @@ -0,0 +1,25 @@ +dependentDestructuredVariablesNoCrash2.ts(3,9): error TS7010: '(Missing)', which lacks return-type annotation, implicitly has an 'any' return type. +dependentDestructuredVariablesNoCrash2.ts(3,10): error TS1003: Identifier expected. +dependentDestructuredVariablesNoCrash2.ts(3,11): error TS2488: Type 'string | undefined' must have a '[Symbol.iterator]()' method that returns an iterator. +dependentDestructuredVariablesNoCrash2.ts(3,11): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. +dependentDestructuredVariablesNoCrash2.ts(3,12): error TS7022: 'undefined' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. +dependentDestructuredVariablesNoCrash2.ts(3,54): error TS2373: Parameter '[undefined, unknown]' cannot reference identifier 'undefined' declared after it. + + +==== dependentDestructuredVariablesNoCrash2.ts (6 errors) ==== + // https://github.com/microsoft/TypeScript/issues/63091 + + function ([undefined, unknown]: string | undefined = undefined) + +!!! error TS7010: '(Missing)', which lacks return-type annotation, implicitly has an 'any' return type. + ~ +!!! error TS1003: Identifier expected. + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2488: Type 'string | undefined' must have a '[Symbol.iterator]()' method that returns an iterator. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation. + ~~~~~~~~~ +!!! error TS7022: 'undefined' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. + ~~~~~~~~~ +!!! error TS2373: Parameter '[undefined, unknown]' cannot reference identifier 'undefined' declared after it. + \ No newline at end of file diff --git a/tests/baselines/reference/dependentDestructuredVariablesNoCrash2.js b/tests/baselines/reference/dependentDestructuredVariablesNoCrash2.js new file mode 100644 index 0000000000000..c52676c55b4cc --- /dev/null +++ b/tests/baselines/reference/dependentDestructuredVariablesNoCrash2.js @@ -0,0 +1,15 @@ +//// [tests/cases/conformance/controlFlow/dependentDestructuredVariablesNoCrash2.ts] //// + +//// [dependentDestructuredVariablesNoCrash2.ts] +// https://github.com/microsoft/TypeScript/issues/63091 + +function ([undefined, unknown]: string | undefined = undefined) + + +//// [dependentDestructuredVariablesNoCrash2.js] +"use strict"; +// https://github.com/microsoft/TypeScript/issues/63091 + + +//// [dependentDestructuredVariablesNoCrash2.d.ts] +declare function ([undefined, unknown]?: string | undefined): any; diff --git a/tests/baselines/reference/dependentDestructuredVariablesNoCrash2.symbols b/tests/baselines/reference/dependentDestructuredVariablesNoCrash2.symbols new file mode 100644 index 0000000000000..9d6f183dd8d3f --- /dev/null +++ b/tests/baselines/reference/dependentDestructuredVariablesNoCrash2.symbols @@ -0,0 +1,11 @@ +//// [tests/cases/conformance/controlFlow/dependentDestructuredVariablesNoCrash2.ts] //// + +=== dependentDestructuredVariablesNoCrash2.ts === +// https://github.com/microsoft/TypeScript/issues/63091 + +function ([undefined, unknown]: string | undefined = undefined) +> : Symbol((Missing), Decl(dependentDestructuredVariablesNoCrash2.ts, 0, 0)) +>undefined : Symbol(undefined, Decl(dependentDestructuredVariablesNoCrash2.ts, 2, 11)) +>unknown : Symbol(unknown, Decl(dependentDestructuredVariablesNoCrash2.ts, 2, 21)) +>undefined : Symbol(undefined, Decl(dependentDestructuredVariablesNoCrash2.ts, 2, 11)) + diff --git a/tests/baselines/reference/dependentDestructuredVariablesNoCrash2.types b/tests/baselines/reference/dependentDestructuredVariablesNoCrash2.types new file mode 100644 index 0000000000000..c8f6c6c0ac86e --- /dev/null +++ b/tests/baselines/reference/dependentDestructuredVariablesNoCrash2.types @@ -0,0 +1,15 @@ +//// [tests/cases/conformance/controlFlow/dependentDestructuredVariablesNoCrash2.ts] //// + +=== dependentDestructuredVariablesNoCrash2.ts === +// https://github.com/microsoft/TypeScript/issues/63091 + +function ([undefined, unknown]: string | undefined = undefined) +> : ([undefined, unknown]?: string | undefined) => any +> : ^ ^^^ ^^^^^^^^ +>undefined : any +> : ^^^ +>unknown : any +> : ^^^ +>undefined : any +> : ^^^ + diff --git a/tests/baselines/reference/dependentDestructuredVariablesNoCrash3.errors.txt b/tests/baselines/reference/dependentDestructuredVariablesNoCrash3.errors.txt new file mode 100644 index 0000000000000..3dbfc1dc6d43a --- /dev/null +++ b/tests/baselines/reference/dependentDestructuredVariablesNoCrash3.errors.txt @@ -0,0 +1,26 @@ +dependentDestructuredVariablesNoCrash3.ts(3,7): error TS2488: Type 'boolean' must have a '[Symbol.iterator]()' method that returns an iterator. +dependentDestructuredVariablesNoCrash3.ts(3,30): error TS7022: 'string' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. +dependentDestructuredVariablesNoCrash3.ts(3,69): error TS2582: Cannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`. +dependentDestructuredVariablesNoCrash3.ts(3,86): error TS2448: Block-scoped variable 'string' used before its declaration. +dependentDestructuredVariablesNoCrash3.ts(3,95): error TS1109: Expression expected. +dependentDestructuredVariablesNoCrash3.ts(3,97): error TS2339: Property 'ranges' does not exist on type 'boolean'. + + +==== dependentDestructuredVariablesNoCrash3.ts (6 errors) ==== + // https://github.com/microsoft/TypeScript/issues/63093 + + const [r0Def, r0, r1Def, as, string, r1, r2, r3Def, r3]: boolean = (test as number < string > ).ranges(); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2488: Type 'boolean' must have a '[Symbol.iterator]()' method that returns an iterator. + ~~~~~~ +!!! error TS7022: 'string' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. + ~~~~ +!!! error TS2582: Cannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`. + ~~~~~~ +!!! error TS2448: Block-scoped variable 'string' used before its declaration. +!!! related TS2728 dependentDestructuredVariablesNoCrash3.ts:3:30: 'string' is declared here. + ~ +!!! error TS1109: Expression expected. + ~~~~~~ +!!! error TS2339: Property 'ranges' does not exist on type 'boolean'. + \ No newline at end of file diff --git a/tests/baselines/reference/dependentDestructuredVariablesNoCrash3.js b/tests/baselines/reference/dependentDestructuredVariablesNoCrash3.js new file mode 100644 index 0000000000000..08565e0aa66d3 --- /dev/null +++ b/tests/baselines/reference/dependentDestructuredVariablesNoCrash3.js @@ -0,0 +1,16 @@ +//// [tests/cases/conformance/controlFlow/dependentDestructuredVariablesNoCrash3.ts] //// + +//// [dependentDestructuredVariablesNoCrash3.ts] +// https://github.com/microsoft/TypeScript/issues/63093 + +const [r0Def, r0, r1Def, as, string, r1, r2, r3Def, r3]: boolean = (test as number < string > ).ranges(); + + +//// [dependentDestructuredVariablesNoCrash3.js] +"use strict"; +// https://github.com/microsoft/TypeScript/issues/63093 +const [r0Def, r0, r1Def, as, string, r1, r2, r3Def, r3] = (test < string > ).ranges(); + + +//// [dependentDestructuredVariablesNoCrash3.d.ts] +declare const r0Def: any, r0: any, r1Def: any, as: any, string: any, r1: any, r2: any, r3Def: any, r3: any; diff --git a/tests/baselines/reference/dependentDestructuredVariablesNoCrash3.symbols b/tests/baselines/reference/dependentDestructuredVariablesNoCrash3.symbols new file mode 100644 index 0000000000000..0da8e00245b44 --- /dev/null +++ b/tests/baselines/reference/dependentDestructuredVariablesNoCrash3.symbols @@ -0,0 +1,17 @@ +//// [tests/cases/conformance/controlFlow/dependentDestructuredVariablesNoCrash3.ts] //// + +=== dependentDestructuredVariablesNoCrash3.ts === +// https://github.com/microsoft/TypeScript/issues/63093 + +const [r0Def, r0, r1Def, as, string, r1, r2, r3Def, r3]: boolean = (test as number < string > ).ranges(); +>r0Def : Symbol(r0Def, Decl(dependentDestructuredVariablesNoCrash3.ts, 2, 7)) +>r0 : Symbol(r0, Decl(dependentDestructuredVariablesNoCrash3.ts, 2, 13)) +>r1Def : Symbol(r1Def, Decl(dependentDestructuredVariablesNoCrash3.ts, 2, 17)) +>as : Symbol(as, Decl(dependentDestructuredVariablesNoCrash3.ts, 2, 24)) +>string : Symbol(string, Decl(dependentDestructuredVariablesNoCrash3.ts, 2, 28)) +>r1 : Symbol(r1, Decl(dependentDestructuredVariablesNoCrash3.ts, 2, 36)) +>r2 : Symbol(r2, Decl(dependentDestructuredVariablesNoCrash3.ts, 2, 40)) +>r3Def : Symbol(r3Def, Decl(dependentDestructuredVariablesNoCrash3.ts, 2, 44)) +>r3 : Symbol(r3, Decl(dependentDestructuredVariablesNoCrash3.ts, 2, 51)) +>string : Symbol(string, Decl(dependentDestructuredVariablesNoCrash3.ts, 2, 28)) + diff --git a/tests/baselines/reference/dependentDestructuredVariablesNoCrash3.types b/tests/baselines/reference/dependentDestructuredVariablesNoCrash3.types new file mode 100644 index 0000000000000..9c3370afc30a2 --- /dev/null +++ b/tests/baselines/reference/dependentDestructuredVariablesNoCrash3.types @@ -0,0 +1,45 @@ +//// [tests/cases/conformance/controlFlow/dependentDestructuredVariablesNoCrash3.ts] //// + +=== dependentDestructuredVariablesNoCrash3.ts === +// https://github.com/microsoft/TypeScript/issues/63093 + +const [r0Def, r0, r1Def, as, string, r1, r2, r3Def, r3]: boolean = (test as number < string > ).ranges(); +>r0Def : any +> : ^^^ +>r0 : any +> : ^^^ +>r1Def : any +> : ^^^ +>as : any +> : ^^^ +>string : any +> : ^^^ +>r1 : any +> : ^^^ +>r2 : any +> : ^^^ +>r3Def : any +> : ^^^ +>r3 : any +> : ^^^ +>(test as number < string > ).ranges() : any +> : ^^^ +>(test as number < string > ).ranges : any +> : ^^^ +>(test as number < string > ) : boolean +> : ^^^^^^^ +>test as number < string > : boolean +> : ^^^^^^^ +>test as number < string : boolean +> : ^^^^^^^ +>test as number : number +> : ^^^^^^ +>test : any +> : ^^^ +>string : any +> : ^^^ +> : any +> : ^^^ +>ranges : any +> : ^^^ + diff --git a/tests/baselines/reference/dependentDestructuredVariablesRefereinceInDeclaration1.errors.txt b/tests/baselines/reference/dependentDestructuredVariablesRefereinceInDeclaration1.errors.txt new file mode 100644 index 0000000000000..52b1694956502 --- /dev/null +++ b/tests/baselines/reference/dependentDestructuredVariablesRefereinceInDeclaration1.errors.txt @@ -0,0 +1,148 @@ +dependentDestructuredVariablesRefereinceInDeclaration1.ts(4,9): error TS2322: Type '{ c: number; f: any; }' is not assignable to type 'string | number'. +dependentDestructuredVariablesRefereinceInDeclaration1.ts(4,11): error TS2339: Property 'c' does not exist on type 'string | number'. +dependentDestructuredVariablesRefereinceInDeclaration1.ts(4,14): error TS2339: Property 'f' does not exist on type 'string | number'. +dependentDestructuredVariablesRefereinceInDeclaration1.ts(4,14): error TS7022: 'f' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. +dependentDestructuredVariablesRefereinceInDeclaration1.ts(4,45): error TS2448: Block-scoped variable 'f' used before its declaration. +dependentDestructuredVariablesRefereinceInDeclaration1.ts(9,9): error TS2322: Type '{ c: number; f: () => any; }' is not assignable to type 'string | number'. +dependentDestructuredVariablesRefereinceInDeclaration1.ts(9,11): error TS2339: Property 'c' does not exist on type 'string | number'. +dependentDestructuredVariablesRefereinceInDeclaration1.ts(9,14): error TS2339: Property 'f' does not exist on type 'string | number'. +dependentDestructuredVariablesRefereinceInDeclaration1.ts(14,9): error TS2322: Type '{ c: number; f: number; g: number; }' is not assignable to type 'string | number'. +dependentDestructuredVariablesRefereinceInDeclaration1.ts(14,11): error TS2339: Property 'c' does not exist on type 'string | number'. +dependentDestructuredVariablesRefereinceInDeclaration1.ts(14,14): error TS2339: Property 'f' does not exist on type 'string | number'. +dependentDestructuredVariablesRefereinceInDeclaration1.ts(14,17): error TS2339: Property 'g' does not exist on type 'string | number'. +dependentDestructuredVariablesRefereinceInDeclaration1.ts(20,9): error TS2322: Type '{ c: number; f: number; }' is not assignable to type 'string | number'. +dependentDestructuredVariablesRefereinceInDeclaration1.ts(20,11): error TS2339: Property 'c' does not exist on type 'string | number'. +dependentDestructuredVariablesRefereinceInDeclaration1.ts(20,14): error TS2339: Property 'f' does not exist on type 'string | number'. +dependentDestructuredVariablesRefereinceInDeclaration1.ts(20,14): error TS2451: Cannot redeclare block-scoped variable 'f'. +dependentDestructuredVariablesRefereinceInDeclaration1.ts(20,17): error TS2339: Property 'f' does not exist on type 'string | number'. +dependentDestructuredVariablesRefereinceInDeclaration1.ts(20,17): error TS2451: Cannot redeclare block-scoped variable 'f'. +dependentDestructuredVariablesRefereinceInDeclaration1.ts(25,9): error TS2322: Type '{ c: number; f: number; }' is not assignable to type 'string | number'. +dependentDestructuredVariablesRefereinceInDeclaration1.ts(25,11): error TS2339: Property 'c' does not exist on type 'string | number'. +dependentDestructuredVariablesRefereinceInDeclaration1.ts(25,14): error TS2339: Property 'f' does not exist on type 'string | number'. +dependentDestructuredVariablesRefereinceInDeclaration1.ts(25,17): error TS2339: Property 'f' does not exist on type 'string | number'. +dependentDestructuredVariablesRefereinceInDeclaration1.ts(30,14): error TS7022: 'f' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. +dependentDestructuredVariablesRefereinceInDeclaration1.ts(30,71): error TS2448: Block-scoped variable 'f' used before its declaration. +dependentDestructuredVariablesRefereinceInDeclaration1.ts(58,14): error TS2451: Cannot redeclare block-scoped variable 'f'. +dependentDestructuredVariablesRefereinceInDeclaration1.ts(58,17): error TS2451: Cannot redeclare block-scoped variable 'f'. + + +==== dependentDestructuredVariablesRefereinceInDeclaration1.ts (26 errors) ==== + // https://github.com/microsoft/TypeScript/issues/62993 + + { + const { c, f }: string | number = { c: 0, f }; + ~~~~~~~~ +!!! error TS2322: Type '{ c: number; f: any; }' is not assignable to type 'string | number'. + ~ +!!! error TS2339: Property 'c' does not exist on type 'string | number'. + ~ +!!! error TS2339: Property 'f' does not exist on type 'string | number'. + ~ +!!! error TS7022: 'f' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. + ~ +!!! error TS2448: Block-scoped variable 'f' used before its declaration. +!!! related TS2728 dependentDestructuredVariablesRefereinceInDeclaration1.ts:4:14: 'f' is declared here. + f; + } + + { + const { c, f }: string | number = { c: 0, f: () => f }; + ~~~~~~~~ +!!! error TS2322: Type '{ c: number; f: () => any; }' is not assignable to type 'string | number'. + ~ +!!! error TS2339: Property 'c' does not exist on type 'string | number'. + ~ +!!! error TS2339: Property 'f' does not exist on type 'string | number'. + f; + } + + { + const { c, f, g = f }: string | number = { c: 0, f: 0, g: 0 }; + ~~~~~~~~~~~~~~~ +!!! error TS2322: Type '{ c: number; f: number; g: number; }' is not assignable to type 'string | number'. + ~ +!!! error TS2339: Property 'c' does not exist on type 'string | number'. + ~ +!!! error TS2339: Property 'f' does not exist on type 'string | number'. + ~ +!!! error TS2339: Property 'g' does not exist on type 'string | number'. + f; + g; + } + + { + const { c, f, f }: string | number = { c: 0, f: 0 }; + ~~~~~~~~~~~ +!!! error TS2322: Type '{ c: number; f: number; }' is not assignable to type 'string | number'. + ~ +!!! error TS2339: Property 'c' does not exist on type 'string | number'. + ~ +!!! error TS2339: Property 'f' does not exist on type 'string | number'. + ~ +!!! error TS2451: Cannot redeclare block-scoped variable 'f'. + ~ +!!! error TS2339: Property 'f' does not exist on type 'string | number'. + ~ +!!! error TS2451: Cannot redeclare block-scoped variable 'f'. + f; + } + + { + const { c, f, f: g }: string | number = { c: 0, f: 0 }; + ~~~~~~~~~~~~~~ +!!! error TS2322: Type '{ c: number; f: number; }' is not assignable to type 'string | number'. + ~ +!!! error TS2339: Property 'c' does not exist on type 'string | number'. + ~ +!!! error TS2339: Property 'f' does not exist on type 'string | number'. + ~ +!!! error TS2339: Property 'f' does not exist on type 'string | number'. + g; + } + + { + const { c, f }: { c: 0; f: number } | { c: 1; f: string } = { c: 0, f }; + ~ +!!! error TS7022: 'f' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. + ~ +!!! error TS2448: Block-scoped variable 'f' used before its declaration. +!!! related TS2728 dependentDestructuredVariablesRefereinceInDeclaration1.ts:30:14: 'f' is declared here. + f; + } + + { + const { c, f }: { c: 0; f: () => unknown } | { c: 1; f: string } = { + c: 0, + f: () => f, + }; + f; + } + + { + const { + c, + f, + g = f, + }: + | { c: 0; f: bigint; g?: bigint | number } + | { c: 1; f: number; g: string } = { + c: 0, + f: 10n, + }; + f; + g; + } + + { + const { c, f, f }: { c: 0; f: number } | { c: 1; f: string } = { c: 0, f: 0 }; + ~ +!!! error TS2451: Cannot redeclare block-scoped variable 'f'. + ~ +!!! error TS2451: Cannot redeclare block-scoped variable 'f'. + f; + } + + { + const { c, f, f: g }: { c: 0; f: number } | { c: 1; f: string } = { c: 0, f: 0 }; + g; + } \ No newline at end of file diff --git a/tests/baselines/reference/dependentDestructuredVariablesRefereinceInDeclaration1.symbols b/tests/baselines/reference/dependentDestructuredVariablesRefereinceInDeclaration1.symbols new file mode 100644 index 0000000000000..50588fd7598ce --- /dev/null +++ b/tests/baselines/reference/dependentDestructuredVariablesRefereinceInDeclaration1.symbols @@ -0,0 +1,174 @@ +//// [tests/cases/conformance/controlFlow/dependentDestructuredVariablesRefereinceInDeclaration1.ts] //// + +=== dependentDestructuredVariablesRefereinceInDeclaration1.ts === +// https://github.com/microsoft/TypeScript/issues/62993 + +{ + const { c, f }: string | number = { c: 0, f }; +>c : Symbol(c, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 3, 9)) +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 3, 12)) +>c : Symbol(c, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 3, 37)) +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 3, 43)) + + f; +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 3, 12)) +} + +{ + const { c, f }: string | number = { c: 0, f: () => f }; +>c : Symbol(c, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 8, 9)) +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 8, 12)) +>c : Symbol(c, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 8, 37)) +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 8, 43)) +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 8, 12)) + + f; +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 8, 12)) +} + +{ + const { c, f, g = f }: string | number = { c: 0, f: 0, g: 0 }; +>c : Symbol(c, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 13, 9)) +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 13, 12)) +>g : Symbol(g, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 13, 15)) +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 13, 12)) +>c : Symbol(c, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 13, 44)) +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 13, 50)) +>g : Symbol(g, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 13, 56)) + + f; +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 13, 12)) + + g; +>g : Symbol(g, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 13, 15)) +} + +{ + const { c, f, f }: string | number = { c: 0, f: 0 }; +>c : Symbol(c, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 19, 9)) +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 19, 12)) +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 19, 15)) +>c : Symbol(c, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 19, 40)) +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 19, 46)) + + f; +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 19, 12)) +} + +{ + const { c, f, f: g }: string | number = { c: 0, f: 0 }; +>c : Symbol(c, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 24, 9)) +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 24, 12)) +>g : Symbol(g, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 24, 15)) +>c : Symbol(c, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 24, 43)) +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 24, 49)) + + g; +>g : Symbol(g, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 24, 15)) +} + +{ + const { c, f }: { c: 0; f: number } | { c: 1; f: string } = { c: 0, f }; +>c : Symbol(c, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 29, 9)) +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 29, 12)) +>c : Symbol(c, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 29, 19)) +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 29, 25)) +>c : Symbol(c, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 29, 41)) +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 29, 47)) +>c : Symbol(c, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 29, 63)) +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 29, 69)) + + f; +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 29, 12)) +} + +{ + const { c, f }: { c: 0; f: () => unknown } | { c: 1; f: string } = { +>c : Symbol(c, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 34, 9)) +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 34, 12)) +>c : Symbol(c, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 34, 19)) +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 34, 25)) +>c : Symbol(c, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 34, 48)) +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 34, 54)) + + c: 0, +>c : Symbol(c, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 34, 70)) + + f: () => f, +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 35, 9)) +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 34, 12)) + + }; + f; +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 34, 12)) +} + +{ + const { + c, +>c : Symbol(c, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 42, 9)) + + f, +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 43, 6)) + + g = f, +>g : Symbol(g, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 44, 6)) +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 43, 6)) + + }: + | { c: 0; f: bigint; g?: bigint | number } +>c : Symbol(c, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 47, 7)) +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 47, 13)) +>g : Symbol(g, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 47, 24)) + + | { c: 1; f: number; g: string } = { +>c : Symbol(c, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 48, 7)) +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 48, 13)) +>g : Symbol(g, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 48, 24)) + + c: 0, +>c : Symbol(c, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 48, 40)) + + f: 10n, +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 49, 9)) + + }; + f; +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 43, 6)) + + g; +>g : Symbol(g, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 44, 6)) +} + +{ + const { c, f, f }: { c: 0; f: number } | { c: 1; f: string } = { c: 0, f: 0 }; +>c : Symbol(c, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 57, 9)) +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 57, 12)) +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 57, 15)) +>c : Symbol(c, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 57, 22)) +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 57, 28)) +>c : Symbol(c, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 57, 44)) +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 57, 50)) +>c : Symbol(c, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 57, 66)) +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 57, 72)) + + f; +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 57, 12)) +} + +{ + const { c, f, f: g }: { c: 0; f: number } | { c: 1; f: string } = { c: 0, f: 0 }; +>c : Symbol(c, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 62, 9)) +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 62, 12)) +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 62, 31), Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 62, 53)) +>g : Symbol(g, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 62, 15)) +>c : Symbol(c, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 62, 25)) +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 62, 31)) +>c : Symbol(c, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 62, 47)) +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 62, 53)) +>c : Symbol(c, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 62, 69)) +>f : Symbol(f, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 62, 75)) + + g; +>g : Symbol(g, Decl(dependentDestructuredVariablesRefereinceInDeclaration1.ts, 62, 15)) +} diff --git a/tests/baselines/reference/dependentDestructuredVariablesRefereinceInDeclaration1.types b/tests/baselines/reference/dependentDestructuredVariablesRefereinceInDeclaration1.types new file mode 100644 index 0000000000000..2bad97d739b97 --- /dev/null +++ b/tests/baselines/reference/dependentDestructuredVariablesRefereinceInDeclaration1.types @@ -0,0 +1,320 @@ +//// [tests/cases/conformance/controlFlow/dependentDestructuredVariablesRefereinceInDeclaration1.ts] //// + +=== dependentDestructuredVariablesRefereinceInDeclaration1.ts === +// https://github.com/microsoft/TypeScript/issues/62993 + +{ + const { c, f }: string | number = { c: 0, f }; +>c : any +> : ^^^ +>f : any +> : ^^^ +>{ c: 0, f } : { c: number; f: any; } +> : ^^^^^^^^^^^^^^^^^^^^^^ +>c : number +> : ^^^^^^ +>0 : 0 +> : ^ +>f : any +> : ^^^ + + f; +>f : any +> : ^^^ +} + +{ + const { c, f }: string | number = { c: 0, f: () => f }; +>c : any +> : ^^^ +>f : any +> : ^^^ +>{ c: 0, f: () => f } : { c: number; f: () => any; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>c : number +> : ^^^^^^ +>0 : 0 +> : ^ +>f : () => any +> : ^^^^^^^^^ +>() => f : () => any +> : ^^^^^^^^^ +>f : any +> : ^^^ + + f; +>f : any +> : ^^^ +} + +{ + const { c, f, g = f }: string | number = { c: 0, f: 0, g: 0 }; +>c : any +> : ^^^ +>f : any +> : ^^^ +>g : any +> : ^^^ +>f : any +> : ^^^ +>{ c: 0, f: 0, g: 0 } : { c: number; f: number; g: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>c : number +> : ^^^^^^ +>0 : 0 +> : ^ +>f : number +> : ^^^^^^ +>0 : 0 +> : ^ +>g : number +> : ^^^^^^ +>0 : 0 +> : ^ + + f; +>f : any +> : ^^^ + + g; +>g : any +> : ^^^ +} + +{ + const { c, f, f }: string | number = { c: 0, f: 0 }; +>c : any +> : ^^^ +>f : any +> : ^^^ +>f : any +> : ^^^ +>{ c: 0, f: 0 } : { c: number; f: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^ +>c : number +> : ^^^^^^ +>0 : 0 +> : ^ +>f : number +> : ^^^^^^ +>0 : 0 +> : ^ + + f; +>f : any +> : ^^^ +} + +{ + const { c, f, f: g }: string | number = { c: 0, f: 0 }; +>c : any +> : ^^^ +>f : any +> : ^^^ +>f : any +> : ^^^ +>g : any +> : ^^^ +>{ c: 0, f: 0 } : { c: number; f: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^ +>c : number +> : ^^^^^^ +>0 : 0 +> : ^ +>f : number +> : ^^^^^^ +>0 : 0 +> : ^ + + g; +>g : any +> : ^^^ +} + +{ + const { c, f }: { c: 0; f: number } | { c: 1; f: string } = { c: 0, f }; +>c : 0 | 1 +> : ^^^^^ +>f : any +> : ^^^ +>c : 0 +> : ^ +>f : number +> : ^^^^^^ +>c : 1 +> : ^ +>f : string +> : ^^^^^^ +>{ c: 0, f } : { c: 0; f: any; } +> : ^^^^^^^^^^^^^^^^^ +>c : 0 +> : ^ +>0 : 0 +> : ^ +>f : any +> : ^^^ + + f; +>f : string | number +> : ^^^^^^^^^^^^^^^ +} + +{ + const { c, f }: { c: 0; f: () => unknown } | { c: 1; f: string } = { +>c : 0 | 1 +> : ^^^^^ +>f : string | (() => unknown) +> : ^^^^^^^^^^^^^^^^ ^ +>c : 0 +> : ^ +>f : () => unknown +> : ^^^^^^ +>c : 1 +> : ^ +>f : string +> : ^^^^^^ +>{ c: 0, f: () => f, } : { c: 0; f: () => string | (() => unknown); } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ + + c: 0, +>c : 0 +> : ^ +>0 : 0 +> : ^ + + f: () => f, +>f : () => string | (() => unknown) +> : ^^^^^^^^^^^^^^^^^^^^^^ ^ +>() => f : () => string | (() => unknown) +> : ^^^^^^^^^^^^^^^^^^^^^^ ^ +>f : string | (() => unknown) +> : ^^^^^^^^^^^^^^^^ ^ + + }; + f; +>f : () => unknown +> : ^^^^^^ +} + +{ + const { + c, +>c : 0 | 1 +> : ^^^^^ + + f, +>f : number | bigint +> : ^^^^^^^^^^^^^^^ + + g = f, +>g : string | number | bigint +> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>f : number | bigint +> : ^^^^^^^^^^^^^^^ + + }: + | { c: 0; f: bigint; g?: bigint | number } +>c : 0 +> : ^ +>f : bigint +> : ^^^^^^ +>g : number | bigint | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + | { c: 1; f: number; g: string } = { +>c : 1 +> : ^ +>f : number +> : ^^^^^^ +>g : string +> : ^^^^^^ +>{ c: 0, f: 10n, } : { c: 0; f: bigint; } +> : ^^^^^^^^^^^^^^^^^^^^ + + c: 0, +>c : 0 +> : ^ +>0 : 0 +> : ^ + + f: 10n, +>f : bigint +> : ^^^^^^ +>10n : 10n +> : ^^^ + + }; + f; +>f : bigint +> : ^^^^^^ + + g; +>g : string | number | bigint +> : ^^^^^^^^^^^^^^^^^^^^^^^^ +} + +{ + const { c, f, f }: { c: 0; f: number } | { c: 1; f: string } = { c: 0, f: 0 }; +>c : 0 | 1 +> : ^^^^^ +>f : string | number +> : ^^^^^^^^^^^^^^^ +>f : string | number +> : ^^^^^^^^^^^^^^^ +>c : 0 +> : ^ +>f : number +> : ^^^^^^ +>c : 1 +> : ^ +>f : string +> : ^^^^^^ +>{ c: 0, f: 0 } : { c: 0; f: number; } +> : ^^^^^^^^^^^^^^^^^^^^ +>c : 0 +> : ^ +>0 : 0 +> : ^ +>f : number +> : ^^^^^^ +>0 : 0 +> : ^ + + f; +>f : number +> : ^^^^^^ +} + +{ + const { c, f, f: g }: { c: 0; f: number } | { c: 1; f: string } = { c: 0, f: 0 }; +>c : 0 | 1 +> : ^^^^^ +>f : string | number +> : ^^^^^^^^^^^^^^^ +>f : any +> : ^^^ +>g : string | number +> : ^^^^^^^^^^^^^^^ +>c : 0 +> : ^ +>f : number +> : ^^^^^^ +>c : 1 +> : ^ +>f : string +> : ^^^^^^ +>{ c: 0, f: 0 } : { c: 0; f: number; } +> : ^^^^^^^^^^^^^^^^^^^^ +>c : 0 +> : ^ +>0 : 0 +> : ^ +>f : number +> : ^^^^^^ +>0 : 0 +> : ^ + + g; +>g : number +> : ^^^^^^ +} diff --git a/tests/cases/conformance/controlFlow/dependentDestructuredVariablesNoCrash1.ts b/tests/cases/conformance/controlFlow/dependentDestructuredVariablesNoCrash1.ts new file mode 100644 index 0000000000000..86e6ca00e9c4c --- /dev/null +++ b/tests/cases/conformance/controlFlow/dependentDestructuredVariablesNoCrash1.ts @@ -0,0 +1,8 @@ +// @strict: true +// @declaration: true + +// https://github.com/microsoft/TypeScript/issues/63044 + +function f() + +function f([first, undefined]?: () => any = undefined) {} diff --git a/tests/cases/conformance/controlFlow/dependentDestructuredVariablesNoCrash2.ts b/tests/cases/conformance/controlFlow/dependentDestructuredVariablesNoCrash2.ts new file mode 100644 index 0000000000000..e0ed97eeb8330 --- /dev/null +++ b/tests/cases/conformance/controlFlow/dependentDestructuredVariablesNoCrash2.ts @@ -0,0 +1,6 @@ +// @strict: true +// @declaration: true + +// https://github.com/microsoft/TypeScript/issues/63091 + +function ([undefined, unknown]: string | undefined = undefined) diff --git a/tests/cases/conformance/controlFlow/dependentDestructuredVariablesNoCrash3.ts b/tests/cases/conformance/controlFlow/dependentDestructuredVariablesNoCrash3.ts new file mode 100644 index 0000000000000..22b223240f4d7 --- /dev/null +++ b/tests/cases/conformance/controlFlow/dependentDestructuredVariablesNoCrash3.ts @@ -0,0 +1,6 @@ +// @strict: true +// @declaration: true + +// https://github.com/microsoft/TypeScript/issues/63093 + +const [r0Def, r0, r1Def, as, string, r1, r2, r3Def, r3]: boolean = (test as number < string > ).ranges(); diff --git a/tests/cases/conformance/controlFlow/dependentDestructuredVariablesRefereinceInDeclaration1.ts b/tests/cases/conformance/controlFlow/dependentDestructuredVariablesRefereinceInDeclaration1.ts new file mode 100644 index 0000000000000..9df85955b43ce --- /dev/null +++ b/tests/cases/conformance/controlFlow/dependentDestructuredVariablesRefereinceInDeclaration1.ts @@ -0,0 +1,69 @@ +// @strict: true +// @target: esnext +// @noEmit: true + +// https://github.com/microsoft/TypeScript/issues/62993 + +{ + const { c, f }: string | number = { c: 0, f }; + f; +} + +{ + const { c, f }: string | number = { c: 0, f: () => f }; + f; +} + +{ + const { c, f, g = f }: string | number = { c: 0, f: 0, g: 0 }; + f; + g; +} + +{ + const { c, f, f }: string | number = { c: 0, f: 0 }; + f; +} + +{ + const { c, f, f: g }: string | number = { c: 0, f: 0 }; + g; +} + +{ + const { c, f }: { c: 0; f: number } | { c: 1; f: string } = { c: 0, f }; + f; +} + +{ + const { c, f }: { c: 0; f: () => unknown } | { c: 1; f: string } = { + c: 0, + f: () => f, + }; + f; +} + +{ + const { + c, + f, + g = f, + }: + | { c: 0; f: bigint; g?: bigint | number } + | { c: 1; f: number; g: string } = { + c: 0, + f: 10n, + }; + f; + g; +} + +{ + const { c, f, f }: { c: 0; f: number } | { c: 1; f: string } = { c: 0, f: 0 }; + f; +} + +{ + const { c, f, f: g }: { c: 0; f: number } | { c: 1; f: string } = { c: 0, f: 0 }; + g; +} \ No newline at end of file